Repository navigation
Expand file tree
/
Copy pathmain.uts
More file actions
318 lines (310 loc) · 11.3 KB
/
Copy pathmain.uts
File metadata and controls
318 lines (310 loc) · 11.3 KB
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
30
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import App from './App.uvue'
import { createSSRApp } from 'vue'
import CompForAppComponent from '@/components/CompForAppComponent.uvue'
import GlobalMixinComp1 from '@/pages/component-instance/mixins/components/GlobalMixinComp1.uvue';
import GlobalChildMixinComp1 from '@/pages/component-instance/mixins/components/GlobalChildMixinComp1.uvue';
import GlobalMixinComp2 from '@/pages/component-instance/mixins/components/GlobalMixinComp2.uvue';
import GlobalChildMixinComp2 from '@/pages/component-instance/mixins/components/GlobalChildMixinComp2.uvue';
import MixinCompForGlobalMixin from '@/pages/component-instance/mixins/components/MixinCompForGlobalMixin.uvue';
import MixinCompForGlobalChildMixin from '@/pages/component-instance/mixins/components/MixinCompForGlobalChildMixin.uvue';
import plugin1 from '@/plugins/plugin1.uts'
import plugin2 from '@/plugins/plugin2.uts'
import plugin3 from '@/plugins/plugin3.uts'
import plugin4 from '@/plugins/plugin4.uts'
import CompForPlugin from '@/components/CompForPlugin.uvue'
// #ifdef MP
import CompForPluginCopy from '@/components/CompForPluginCopy.uvue'
// #endif
// 仅引用类型,模板中不使用,也要保证不报错
let testType1 : TestType1ComponentPublicInstance | null = null
export function createApp() {
const app = createSSRApp(App)
console.log(testType1)
app.component('CompForAppComponent', CompForAppComponent)
app.provide('globalProvideMsg', 'global provide message')
const globalChildMixin = defineMixin({
components: { GlobalChildMixinComp1, MixinComp: MixinCompForGlobalChildMixin },
props: {
globalChildMixinProp1: {
type: String,
default: '通过 defineMixin 定义全局 child mixin props'
},
namesakeChildMixinProp: {
type: String,
default: '通过 defineMixin 定义全局同名 child mixin props'
}
},
data() {
return {
namesakeChildMixinDataMsg: '通过 defineMixin 定义全局同名 child mixin data',
globalChildMixinDataMsg1: '通过 defineMixin 定义全局 child mixin data',
globalChildMixinOnloadMsg1: '',
globalChildMixinOnloadTime1: 0,
globalChildMixinWatchMsg1: '',
}
},
computed: {
globalChildMixinComputed1(): string {
const res = `通过 defineMixin 定义全局 child mixin computed, 更新后的 globalChildMixinOnloadMsg1: ${this.globalChildMixinOnloadMsg1}`
console.log(res)
return res
},
namesakeChildMixinComputed(): string {
const res = '通过 defineMixin 定义全局同名 child mixin computed'
console.log(res)
return res
}
},
watch: {
globalMixinOnloadMsg1(newVal: string) {
this.globalChildMixinWatchMsg1 = `通过 defineMixin 定义全局 child mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
console.log(this.globalChildMixinWatchMsg1)
},
},
emits: ['globalChildMixinEmit1'],
onLoad() {
this.globalChildMixinOnloadTime1 = Date.now()
const res = '通过 defineMixin 定义全局 child mixin onLoad'
console.log(res)
this.globalChildMixinOnloadMsg1 = res
},
methods: {
globalChildMixinMethod1(): string {
const res = '通过 defineMixin 定义全局 child mixin method'
console.log(res)
return res
},
namesakeChildMixinMethod(): string {
const res = '通过 defineMixin 定义全局同名 child mixin method'
console.log(res)
return res
},
}
})
const globalMixin = defineMixin({
mixins: [globalChildMixin],
components: { GlobalMixinComp1, MixinComp: MixinCompForGlobalMixin },
props: {
globalMixinProp1: {
type: String,
default: '通过 defineMixin 定义全局 mixin props'
},
namesakeMixinProp: {
type: String,
default: '通过 defineMixin 定义全局同名 mixin props'
}
},
data() {
return {
globalMixinDataMsg1: '通过 defineMixin 定义全局 mixin data',
namesakeMixinDataMsg: '通过 defineMixin 定义全局同名 mixin data',
globalMixinOnloadMsg1: '',
globalMixinOnloadTime1: 0,
globalMixinWatchMsg1: ''
}
},
computed: {
globalMixinComputed1(): string {
const res = `通过 defineMixin 定义全局 mixin computed, 更新后的 globalMixinOnloadMsg1: ${this.globalMixinOnloadMsg1}`
console.log(res)
return res
},
namesakeChildMixinComputed(): string {
const res = '通过 defineMixin 定义全局同名 mixin computed'
console.log(res)
return res
}
},
watch: {
globalMixinOnloadMsg1(newVal: string) {
this.globalMixinWatchMsg1 = `通过 defineMixin 定义全局 mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
console.log(this.globalMixinWatchMsg1)
},
},
emits: ['globalMixinEmit1'],
onLoad() {
this.globalMixinOnloadTime1 = Date.now()
const res = '通过 defineMixin 定义全局 mixin onLoad'
console.log(res)
this.globalMixinOnloadMsg1 = res
},
methods: {
globalMixinMethod1(): string {
const res = '通过 defineMixin 定义全局 mixin method'
console.log(res)
return res
},
namesakeMixinMethod1(): string {
const res = '通过 defineMixin 定义全局同名 mixin method'
console.log(res)
return res
}
}
})
app.mixin({
mixins: [{
components: { GlobalChildMixinComp2 },
props: {
globalChildMixinProp2: {
type: String,
default: '通过字面量定义全局 child mixin props'
},
namesakeChildMixinProp: {
type: String,
default: '通过字面量定义全局同名 child mixin props'
}
},
data() {
return {
namesakeChildMixinDataMsg: '通过字面量定义全局同名 child mixin data',
globalChildMixinDataMsg2: '通过字面量定义全局 child mixin data',
globalChildMixinOnloadMsg2: '',
globalChildMixinOnloadTime2: 0,
globalChildMixinWatchMsg2: ''
}
},
computed: {
globalChildMixinComputed2(): string {
const res = `通过字面量定义全局 child mixin computed, 更新后的 globalChildMixinOnloadMsg2: ${this.globalChildMixinOnloadMsg2}`
console.log(res)
return res
},
namesakeChildMixinComputed(): string {
const res = '通过定义全局同名 child mixin computed'
console.log(res)
return res
}
},
watch: {
globalMixinOnloadMsg1(newVal: string) {
this.globalChildMixinWatchMsg2 = `通过字面量定义全局 child mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
console.log(this.globalChildMixinWatchMsg2)
},
},
emits: ['globalChildMixinEmit2'],
onLoad() {
this.globalChildMixinOnloadTime2 = Date.now()
const res = '通过字面量定义全局 child mixin onLoad'
console.log(res)
this.globalChildMixinOnloadMsg2 = res
},
methods: {
globalChildMixinMethod2(): string {
const res = '通过字面量定义全局 child mixin method'
console.log(res)
return res
},
namesakeChildMixinMethod(): string {
const res = '通过字面量定义全局同名 child mixin method'
console.log(res)
return res
},
}
}],
components: { GlobalMixinComp2 },
props: {
globalMixinProp2: {
type: String,
default: '通过字面量定义全局 mixin props'
},
namesakeMixinProp: {
type: String,
default: '通过字面量定义全局同名 mixin props'
}
},
data() {
return {
globalMixinDataMsg2: '通过字面量定义全局 mixin data',
namesakeMixinDataMsg: '通过字面量定义全局同名 mixin data',
globalMixinOnloadMsg2: '',
globalMixinOnloadTime2: 0,
globalMixinWatchMsg2: ''
}
},
computed: {
globalMixinComputed2(): string {
const res = `通过字面量定义全局 mixin computed, 更新后的 globalMixinOnloadMsg2: ${this.globalMixinOnloadMsg2}`
console.log(res)
return res
},
namesakeChildMixinComputed(): string {
const res = '通过字面量定义全局同名 mixin computed'
console.log(res)
return res
}
},
watch: {
globalMixinOnloadMsg1(newVal: string) {
this.globalMixinWatchMsg2 = `通过字面量定义全局 mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
console.log(this.globalMixinWatchMsg2)
},
},
emits: ['globalMixinEmit2'],
onLoad() {
this.globalMixinOnloadTime2 = Date.now()
const res = '通过字面量定义全局 mixin onLoad'
console.log(res)
this.globalMixinOnloadMsg2 = res
},
methods: {
globalMixinMethod2(): string {
const res = '通过字面量定义全局 mixin method'
console.log(res)
return res
},
namesakeMixinMethod(): string {
const res = '通过字面量定义全局同名 mixin method'
console.log(res)
return res
}
}
})
app.mixin(globalMixin)
app.use(plugin1)
app.use(plugin2)
app.use(plugin3)
app.use(plugin4)
app.use(function (app: VueApp, componentName: string) {
// #ifdef MP
/**
* 此处调整为处理两个问题
* - 小程序不支持动态组件名
* - 小程序两个组件名指向同一个文件时只有一个会生效(TODO 这是Bug后续修复)
*/
app.component('CompForPlugin1', CompForPluginCopy)
// #endif
// #ifndef MP
app.component(componentName, CompForPlugin)
// #endif
}, 'CompForPlugin1')
app.use({
install(app: VueApp, a: string | null, b: string | null) {
app.component('CompForPlugin2', CompForPlugin)
}
}, null, null)
app.config.globalProperties.globalPropertiesStr = 'default string'
app.config.globalProperties.globalPropertiesNum = 0
app.config.globalProperties.globalPropertiesBool = false
app.config.globalProperties.globalPropertiesObj = {
str: 'default globalProperties obj string',
num: 0,
bool: false,
}
app.config.globalProperties.globalPropertiesNull = null as string | null
app.config.globalProperties.globalPropertiesArr = [] as number[]
app.config.globalProperties.globalPropertiesSet = new Set<string>()
app.config.globalProperties.globalPropertiesMap = new Map<string, number>()
app.config.globalProperties.globalPropertiesReactiveObj = reactive({
str: 'default reactive string',
num: 0,
bool: false,
} as UTSJSONObject)
app.config.globalProperties.globalPropertiesFn = function (): string {
console.log('this.globalPropertiesStr', this.globalPropertiesStr)
console.log('this.globalPropertiesNum', this.globalPropertiesNum)
return `globalPropertiesStr: ${this.globalPropertiesStr}, globalPropertiesNum: ${this.globalPropertiesNum}`
}
return {
app
}
}