提交 9368da8a 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

refactor(mixins): 优化变量声明

上级 a7c49e06
...@@ -3,121 +3,121 @@ import ChildMixinComp1 from './components/ChildMixinComp1.uvue' ...@@ -3,121 +3,121 @@ import ChildMixinComp1 from './components/ChildMixinComp1.uvue'
import MixinCompForMixin from './components/MixinCompForMixin.uvue' import MixinCompForMixin from './components/MixinCompForMixin.uvue'
import MixinCompForChildMixin from './components/MixinCompForChildMixin.uvue' import MixinCompForChildMixin from './components/MixinCompForChildMixin.uvue'
export const pageMixin = defineMixin({ const childMixin = defineMixin({
mixins: [childMixin], components: { ChildMixinComp1, MixinComp: MixinCompForChildMixin },
components: { MixinComp1, MixinComp: MixinCompForMixin },
props: { props: {
mixinProp1: { childMixinProp1: {
type: String, type: String,
default: '通过 defineMixin 定义非全局 mixin props' default: '通过 defineMixin 定义非全局 child mixin props'
}, },
namesakeMixinProp: { namesakeChildMixinProp: {
type: String, type: String,
default: '通过 defineMixin 定义非全局同名 mixin props' default: '通过 defineMixin 定义非全局同名 child mixin props'
} }
}, },
data() { data() {
return { return {
mixinDataMsg1: '通过 defineMixin 定义非全局 mixin data', childMixinDataMsg1: '通过 defineMixin 定义非全局 child mixin data',
namesakeMixinDataMsg: '通过 defineMixin 定义非全局同名 mixin data', namesakeChildMixinDataMsg: '通过 defineMixin 定义非全局同名 mixin data',
mixinOnloadMsg1: '', childMixinOnloadMsg1: '',
mixinOnloadTime1: 0, childMixinOnloadTime1: 0,
mixinWatchMsg1: '' childMixinWatchMsg1: ''
} }
}, },
computed: { computed: {
mixinComputed1(): string { childMixinComputed1(): string {
const res = `通过 defineMixin 定义非全局 mixin computed, 更新后的 mixinOnloadMsg1: ${this.mixinOnloadMsg1}` const res = `通过 defineMixin 定义非全局 child mixin computed, 更新后的 childMixinOnloadMsg1: ${this.childMixinOnloadMsg1}`
console.log(res) console.log(res)
return res return res
}, },
namesakeMixinComputed(): string { namesakeChildMixinComputed(): string {
const res = '通过 defineMixin 定义非全局同名 mixin computed' const res = '通过 defineMixin 定义非全局同名 child computed'
console.log(res) console.log(res)
return res return res
} }
}, },
watch: { watch: {
globalMixinOnloadMsg1(newVal: string) { globalMixinOnloadMsg1(newVal: string) {
this.mixinWatchMsg1 = `通过 defineMixin 定义非全局 mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}` this.childMixinWatchMsg1 = `通过 defineMixin 定义非全局 child mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
console.log(this.mixinWatchMsg1) console.log(this.childMixinWatchMsg1)
}, },
}, },
onLoad() { onLoad() {
this.mixinOnloadTime1 = Date.now() this.childMixinOnloadTime1 = Date.now()
const res = '通过 defineMixin 定义非全局 mixin onLoad' const res = '通过 defineMixin 定义非全局 child mixin onLoad'
console.log(res) console.log(res)
this.mixinOnloadMsg1 = res this.childMixinOnloadMsg1 = res
}, },
methods: { methods: {
mixinMethod1(): string { childMixinMethod1(): string {
const res = '通过 defineMixin 定义非全局 mixin method' const res = '通过 defineMixin 定义非全局 child mixin method'
console.log(res) console.log(res)
return res return res
}, },
namesakeMixinMethod(): string { namesakeChildMixinMethod(): string {
const res = '通过 defineMixin 定义非全局同名 mixin method' const res = '通过 defineMixin 定义非全局同名 child mixin method'
console.log(res) console.log(res)
return res return res
} },
} }
}) })
const childMixin = defineMixin({ export const pageMixin = defineMixin({
components: { ChildMixinComp1, MixinComp: MixinCompForChildMixin }, mixins: [childMixin],
components: { MixinComp1, MixinComp: MixinCompForMixin },
props: { props: {
childMixinProp1: { mixinProp1: {
type: String, type: String,
default: '通过 defineMixin 定义非全局 child mixin props' default: '通过 defineMixin 定义非全局 mixin props'
}, },
namesakeChildMixinProp: { namesakeMixinProp: {
type: String, type: String,
default: '通过 defineMixin 定义非全局同名 child mixin props' default: '通过 defineMixin 定义非全局同名 mixin props'
} }
}, },
data() { data() {
return { return {
childMixinDataMsg1: '通过 defineMixin 定义非全局 child mixin data', mixinDataMsg1: '通过 defineMixin 定义非全局 mixin data',
namesakeChildMixinDataMsg: '通过 defineMixin 定义非全局同名 mixin data', namesakeMixinDataMsg: '通过 defineMixin 定义非全局同名 mixin data',
childMixinOnloadMsg1: '', mixinOnloadMsg1: '',
childMixinOnloadTime1: 0, mixinOnloadTime1: 0,
childMixinWatchMsg1: '' mixinWatchMsg1: ''
} }
}, },
computed: { computed: {
childMixinComputed1(): string { mixinComputed1(): string {
const res = `通过 defineMixin 定义非全局 child mixin computed, 更新后的 childMixinOnloadMsg1: ${this.childMixinOnloadMsg1}` const res = `通过 defineMixin 定义非全局 mixin computed, 更新后的 mixinOnloadMsg1: ${this.mixinOnloadMsg1}`
console.log(res) console.log(res)
return res return res
}, },
namesakeChildMixinComputed(): string { namesakeMixinComputed(): string {
const res = '通过 defineMixin 定义非全局同名 child computed' const res = '通过 defineMixin 定义非全局同名 mixin computed'
console.log(res) console.log(res)
return res return res
} }
}, },
watch: { watch: {
globalMixinOnloadMsg1(newVal: string) { globalMixinOnloadMsg1(newVal: string) {
this.childMixinWatchMsg1 = `通过 defineMixin 定义非全局 child mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}` this.mixinWatchMsg1 = `通过 defineMixin 定义非全局 mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
console.log(this.childMixinWatchMsg1) console.log(this.mixinWatchMsg1)
}, },
}, },
onLoad() { onLoad() {
this.childMixinOnloadTime1 = Date.now() this.mixinOnloadTime1 = Date.now()
const res = '通过 defineMixin 定义非全局 child mixin onLoad' const res = '通过 defineMixin 定义非全局 mixin onLoad'
console.log(res) console.log(res)
this.childMixinOnloadMsg1 = res this.mixinOnloadMsg1 = res
}, },
methods: { methods: {
childMixinMethod1(): string { mixinMethod1(): string {
const res = '通过 defineMixin 定义非全局 child mixin method' const res = '通过 defineMixin 定义非全局 mixin method'
console.log(res) console.log(res)
return res return res
}, },
namesakeChildMixinMethod(): string { namesakeMixinMethod(): string {
const res = '通过 defineMixin 定义非全局同名 child mixin method' const res = '通过 defineMixin 定义非全局同名 mixin method'
console.log(res) console.log(res)
return res return res
}, }
} }
}) })
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册