component-for-inject-1.uvue 4.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9
<template>
  <view>
    <text class="uni-common-mt bold">component for inject 1</text>
    <text class="uni-common-mt provide-page-title"
      >providePageTitle: {{ providePageTitle }}</text
    >
    <text class="uni-common-mt alias-provide-page-title"
      >aliasProvidePageTitle: {{ aliasProvidePageTitle }}</text
    >
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
    <text class="uni-common-mt computed-title"
      >computedTitle: {{ computedTitle }}</text
    >
    <text class="uni-common-mt provide-data-obj-title"
      >provideDataObj.title: {{ provideDataObj['title'] }}</text
    >
    <text class="uni-common-mt provide-data-obj-content"
      >provideDataObj.content: {{ provideDataObj['content'] }}</text
    >
    <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 已提交
28 29 30 31 32 33
    <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
    >
34 35 36
    <text class="uni-common-mt provide-page-arr"
      >providePageArr: {{ providePageArr }}</text
    >
DCloud-WZF's avatar
DCloud-WZF 已提交
37 38
   <text class="uni-common-mt provide-page-map"
      >providePageMap: {{ providePageMapObj }}</text
39 40
    >
    <text class="uni-common-mt provide-page-set"
DCloud-WZF's avatar
DCloud-WZF 已提交
41
      >providePageSet: {{ providePageSetArr }}</text
42
    >
DCloud-WZF's avatar
DCloud-WZF 已提交
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
    <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: {
    providePageTitle: {
      type: String,
      default: 'default provide page title'
    },
    aliasProvidePageTitle: {
      type: String,
      from: 'providePageTitle',
      default: 'default alias provide page title'
    },
    computedTitle: {
      type: String,
      default: 'default computed title'
    },
73 74 75
    provideDataObj: {
      type: Object as PropType<UTSJSONObject>,
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
    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 已提交
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
  },
	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 已提交
145 146
}
</script>