main.uts 8.7 KB
Newer Older
H
hdx 已提交
1
import App from './App.uvue'
H
init.  
hdx 已提交
2
import { createSSRApp } from 'vue'
DCloud-WZF's avatar
DCloud-WZF 已提交
3
import CompForAppComponent from '@/components/CompForAppComponent.uvue'
DCloud-WZF's avatar
DCloud-WZF 已提交
4 5 6 7 8 9 10
import GlobalMixinComp1 from '@/pages/composition/mixins/components/GlobalMixinComp1.uvue'
import GlobalChildMixinComp1 from '@/pages/composition/mixins/components/GlobalChildMixinComp1.uvue'
import GlobalMixinComp2 from '@/pages/composition/mixins/components/GlobalMixinComp2.uvue'
import GlobalChildMixinComp2 from '@/pages/composition/mixins/components/GlobalChildMixinComp2.uvue'
import MixinCompForGlobalMixin from '@/pages/composition/mixins/components/MixinCompForGlobalMixin.uvue'
import MixinCompForGlobalChildMixin from '@/pages/composition/mixins/components/MixinCompForGlobalChildMixin.uvue'

H
init.  
hdx 已提交
11 12
export function createApp() {
  const app = createSSRApp(App)
DCloud-WZF's avatar
DCloud-WZF 已提交
13 14 15

  app.component('CompForAppComponent', CompForAppComponent)

DCloud-WZF's avatar
DCloud-WZF 已提交
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
  // #ifdef APP-ANDROID
  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)
  // #endif
H
init.  
hdx 已提交
257 258 259 260 261

  return {
    app
  }
}