component-for-inject-1.uvue 3.5 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6
<template>
  <view>
    <text class="uni-common-mt bold">component for inject 1</text>
    <text class="uni-common-mt alias-provide-page-title"
      >aliasProvidePageTitle: {{ aliasProvidePageTitle }}</text
    >
7 8 9 10 11 12 13 14 15
    <text class="uni-common-mt provide-page-str"
      >providePageStr: {{ providePageStr }}</text
    >
    <text class="uni-common-mt provide-page-num"
      >providePageNum: {{ providePageNum }}</text
    >
    <text class="uni-common-mt provide-page-bool"
      >providePageBool: {{ providePageBool }}</text
    >
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18 19 20 21
    <text class="uni-common-mt provide-page-object-title"
      >providePageObject.title: {{ providePageObject['title'] }}</text
    >
    <text class="uni-common-mt provide-page-object-content"
      >providePageObject.content: {{ providePageObject['content'] }}</text
    >
22 23 24
    <text class="uni-common-mt provide-page-arr"
      >providePageArr: {{ providePageArr }}</text
    >
DCloud-WZF's avatar
DCloud-WZF 已提交
25 26
   <text class="uni-common-mt provide-page-map"
      >providePageMap: {{ providePageMapObj }}</text
27 28
    >
    <text class="uni-common-mt provide-page-set"
DCloud-WZF's avatar
DCloud-WZF 已提交
29
      >providePageSet: {{ providePageSetArr }}</text
30
    >
DCloud-WZF's avatar
DCloud-WZF 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
    <text class="uni-common-mt test-inject-string-default-value"
      >testInjectStringDefaultValue: {{ testInjectStringDefaultValue }}</text
    >
    <text class="uni-common-mt test-inject-object-default-value-title"
      >testInjectObjectDefaultValue.title:
      {{ testInjectObjectDefaultValue['title'] }}</text
    >
    <text class="uni-common-mt test-inject-object-default-value-content"
      >testInjectObjectDefaultValue.content:
      {{ testInjectObjectDefaultValue['content'] }}</text
    >
  </view>
</template>

<script lang="uts">
export default {
  inject: {
    aliasProvidePageTitle: {
      type: String,
      from: 'providePageTitle',
      default: 'default alias provide page title'
    },
    providePageStr: {
      type: String,
      default: 'default provide page str'
    },
    providePageNum: {
      type: Number,
      default: 0
    },
    providePageBool: {
      type: Boolean,
      default: false
    },
    providePageObject: {
      type: Object as PropType<UTSJSONObject>,
      default: (): UTSJSONObject => {
        return {
          title: 'default provide page object title',
          content: 'default provide page object content'
        }
      }
    },
    providePageArr: {
      type: Array as PropType<String[]>,
      default: (): String[] => {
        return ['default provide page arr']
      }
    },
    providePageMap: {
      type: Object as PropType<Map<string, string>>,
      default: (): Map<string, string> => {
        return new Map<string, string>([['key', 'default provide page map']])
      }
    },
    providePageSet: {
      type: Object as PropType<Set<string>>,
      default: (): Set<string> => {
        return new Set<string>(['default provide page set'])
      }
    },
    testInjectStringDefaultValue: {
      type: String,
      default: 'test inject string default value'
    },
    testInjectObjectDefaultValue: {
      type: Object as PropType<UTSJSONObject>,
      default(): UTSJSONObject {
        return {
          title: 'test inject object default value title',
          content: 'test inject object default value content'
        }
      }
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
  },
	computed: {
		providePageMapObj(): UTSJSONObject {
			const obj: UTSJSONObject = {}
			this.providePageMap.forEach((value, key) => {
				obj[key] = value
			})
			return obj
		},
		providePageSetArr(): string[] {
			const arr: string[] = []
			this.providePageSet.forEach((value) => {
				arr.push(value)
			})
			return arr
		}
	}
DCloud-WZF's avatar
DCloud-WZF 已提交
122 123
}
</script>