mixins.uts 3.8 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5
import MixinComp1 from './components/MixinComp1.uvue'
import ChildMixinComp1 from './components/ChildMixinComp1.uvue'
import MixinCompForMixin from './components/MixinCompForMixin.uvue'
import MixinCompForChildMixin from './components/MixinCompForChildMixin.uvue'

DCloud-WZF's avatar
DCloud-WZF 已提交
6 7
const childMixin = defineMixin({
  components: { ChildMixinComp1, MixinComp: MixinCompForChildMixin },
DCloud-WZF's avatar
DCloud-WZF 已提交
8
  props: {
DCloud-WZF's avatar
DCloud-WZF 已提交
9
    childMixinProp1: {
DCloud-WZF's avatar
DCloud-WZF 已提交
10
      type: String,
DCloud-WZF's avatar
DCloud-WZF 已提交
11
      default: '通过 defineMixin 定义非全局 child mixin props'
DCloud-WZF's avatar
DCloud-WZF 已提交
12
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
13
    namesakeChildMixinProp: {
DCloud-WZF's avatar
DCloud-WZF 已提交
14
      type: String,
DCloud-WZF's avatar
DCloud-WZF 已提交
15
      default: '通过 defineMixin 定义非全局同名 child mixin props'
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18 19
    }
  },
  data() {
    return {
DCloud-WZF's avatar
DCloud-WZF 已提交
20 21 22 23 24
      childMixinDataMsg1: '通过 defineMixin 定义非全局 child mixin data',
      namesakeChildMixinDataMsg: '通过 defineMixin 定义非全局同名 mixin data',
      childMixinOnloadMsg1: '',
      childMixinOnloadTime1: 0,
      childMixinWatchMsg1: ''
DCloud-WZF's avatar
DCloud-WZF 已提交
25 26 27
    }
  },
  computed: {
DCloud-WZF's avatar
DCloud-WZF 已提交
28 29
    childMixinComputed1(): string {
      const res = `通过 defineMixin 定义非全局 child mixin computed, 更新后的 childMixinOnloadMsg1: ${this.childMixinOnloadMsg1}`
DCloud-WZF's avatar
DCloud-WZF 已提交
30 31 32
      console.log(res)
      return res
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
33 34
    namesakeChildMixinComputed(): string {
      const res = '通过 defineMixin 定义非全局同名 child computed'
DCloud-WZF's avatar
DCloud-WZF 已提交
35 36 37 38 39 40
      console.log(res)
      return res
    }
  },
  watch: {
    globalMixinOnloadMsg1(newVal: string) {
DCloud-WZF's avatar
DCloud-WZF 已提交
41 42
      this.childMixinWatchMsg1 = `通过 defineMixin 定义非全局 child mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
      console.log(this.childMixinWatchMsg1)
DCloud-WZF's avatar
DCloud-WZF 已提交
43 44 45
    },
  },
  onLoad() {
DCloud-WZF's avatar
DCloud-WZF 已提交
46 47
    this.childMixinOnloadTime1 = Date.now()
    const res = '通过 defineMixin 定义非全局 child mixin onLoad'
DCloud-WZF's avatar
DCloud-WZF 已提交
48
    console.log(res)
DCloud-WZF's avatar
DCloud-WZF 已提交
49
    this.childMixinOnloadMsg1 = res
DCloud-WZF's avatar
DCloud-WZF 已提交
50 51
  },
  methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
52 53
    childMixinMethod1(): string {
      const res = '通过 defineMixin 定义非全局 child mixin method'
DCloud-WZF's avatar
DCloud-WZF 已提交
54 55 56
      console.log(res)
      return res
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
57 58
    namesakeChildMixinMethod(): string {
      const res = '通过 defineMixin 定义非全局同名 child mixin method'
DCloud-WZF's avatar
DCloud-WZF 已提交
59 60
      console.log(res)
      return res
DCloud-WZF's avatar
DCloud-WZF 已提交
61
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
62 63 64
  }
})

DCloud-WZF's avatar
DCloud-WZF 已提交
65 66 67
export const pageMixin = defineMixin({
  mixins: [childMixin],
  components: { MixinComp1, MixinComp: MixinCompForMixin },
DCloud-WZF's avatar
DCloud-WZF 已提交
68
  props: {
DCloud-WZF's avatar
DCloud-WZF 已提交
69
    mixinProp1: {
DCloud-WZF's avatar
DCloud-WZF 已提交
70
      type: String,
DCloud-WZF's avatar
DCloud-WZF 已提交
71
      default: '通过 defineMixin 定义非全局 mixin props'
DCloud-WZF's avatar
DCloud-WZF 已提交
72
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
73
    namesakeMixinProp: {
DCloud-WZF's avatar
DCloud-WZF 已提交
74
      type: String,
DCloud-WZF's avatar
DCloud-WZF 已提交
75
      default: '通过 defineMixin 定义非全局同名 mixin props'
DCloud-WZF's avatar
DCloud-WZF 已提交
76 77 78 79
    }
  },
  data() {
    return {
DCloud-WZF's avatar
DCloud-WZF 已提交
80 81 82 83 84
      mixinDataMsg1: '通过 defineMixin 定义非全局 mixin data',
      namesakeMixinDataMsg: '通过 defineMixin 定义非全局同名 mixin data',
      mixinOnloadMsg1: '',
      mixinOnloadTime1: 0,
      mixinWatchMsg1: ''
DCloud-WZF's avatar
DCloud-WZF 已提交
85 86 87
    }
  },
  computed: {
DCloud-WZF's avatar
DCloud-WZF 已提交
88 89
    mixinComputed1(): string {
      const res = `通过 defineMixin 定义非全局 mixin computed, 更新后的 mixinOnloadMsg1: ${this.mixinOnloadMsg1}`
DCloud-WZF's avatar
DCloud-WZF 已提交
90 91 92
      console.log(res)
      return res
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
93 94
    namesakeMixinComputed(): string {
      const res = '通过 defineMixin 定义非全局同名 mixin computed'
DCloud-WZF's avatar
DCloud-WZF 已提交
95 96 97 98 99 100
      console.log(res)
      return res
    }
  },
  watch: {
    globalMixinOnloadMsg1(newVal: string) {
DCloud-WZF's avatar
DCloud-WZF 已提交
101 102
      this.mixinWatchMsg1 = `通过 defineMixin 定义非全局 mixin watch, 更新后的 globalMixinOnloadMsg1: ${newVal}`
      console.log(this.mixinWatchMsg1)
DCloud-WZF's avatar
DCloud-WZF 已提交
103 104 105
    },
  },
  onLoad() {
DCloud-WZF's avatar
DCloud-WZF 已提交
106 107
    this.mixinOnloadTime1 = Date.now()
    const res = '通过 defineMixin 定义非全局 mixin onLoad'
DCloud-WZF's avatar
DCloud-WZF 已提交
108
    console.log(res)
DCloud-WZF's avatar
DCloud-WZF 已提交
109
    this.mixinOnloadMsg1 = res
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111
  },
  methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
112 113
    mixinMethod1(): string {
      const res = '通过 defineMixin 定义非全局 mixin method'
DCloud-WZF's avatar
DCloud-WZF 已提交
114 115 116
      console.log(res)
      return res
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
117 118
    namesakeMixinMethod(): string {
      const res = '通过 defineMixin 定义非全局同名 mixin method'
DCloud-WZF's avatar
DCloud-WZF 已提交
119 120
      console.log(res)
      return res
DCloud-WZF's avatar
DCloud-WZF 已提交
121
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
122 123
  }
})