inject-composition.uvue 999 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<template>
  <view>
    <text>inject page</text>
    <text class="mt-10 msg">msg: {{msg}}</text>
    <text class="mt-10 num">num: {{num}}</text>
    <text class="mt-10 obj">obj: {{JSON.stringify(obj)}}</text>
    <text class="mt-10 arr">arr: {{JSON.stringify(arr)}}</text>
    <text class="mt-10 fn">fn: {{(fn as () =>  string)()}}</text>
    <text class="mt-10 has-injection-context">hasInjectionContext:
      {{checkHasInjectionContextRes}}</text>
    <button class="mt-10 check-has-injection-context-btn" @click="checkHasInjectionContext">check
      hasInjectionContext</button>
  </view>
</template>

<script setup lang='uts'>
  const msg = inject('msg')
  const num = inject('num')
  const obj = inject('obj')
  const arr = inject('arr')
  const fn = inject('fn')

  const checkHasInjectionContextRes = ref('')

  const checkHasInjectionContext = () => {
    checkHasInjectionContextRes.value = `${hasInjectionContext()}`
  }
  checkHasInjectionContext()
</script>