Comp1.uvue 1.7 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1
<template>
2
  <view class="mt-10" ref="mixin-comp-root">
D
DCloud_LXH 已提交
3 4 5
    <text class="bold">Comp1: inheritAttrs: false</text>
    <text class="mt-10" style="color:#ccc;"
      >rootElementTitle should be null</text
DCloud-WZF's avatar
DCloud-WZF 已提交
6
    >
7
    <text class="mt-10 root-element-title-1">rootElementTitle: {{ rootElementTitle }}</text>
D
DCloud_LXH 已提交
8
    <!-- #ifdef APP -->
9 10
    <text class="mt-10 bold">trigger emitter:</text>
    <button class="mt-10 global-mixin-emit-1" @click="triggerEmitter('globalMixinEmit1')">
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13
      trigger globalMixinEmit1
    </button>
    <button
14
      class="mt-10 global-child-mixin-emit-1"
DCloud-WZF's avatar
DCloud-WZF 已提交
15 16 17
      @click="triggerEmitter('globalChildMixinEmit1')">
      trigger globalChildMixinEmit1
    </button>
18
    <button class="mt-10 global-mixin-emit-2" @click="triggerEmitter('globalMixinEmit2')">
DCloud-WZF's avatar
DCloud-WZF 已提交
19 20 21
      trigger globalMixinEmit2
    </button>
    <button
22
      class="mt-10 global-child-mixin-emit-2"
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25
      @click="triggerEmitter('globalChildMixinEmit2')">
      trigger globalChildMixinEmit2
    </button>
26
    <button class="mt-10 mixin-emit" @click="triggerEmitter('mixinEmit')">
DCloud-WZF's avatar
DCloud-WZF 已提交
27 28
      trigger mixinEmit
    </button>
29
    <button class="mt-10 child-mixin-emit" @click="triggerEmitter('childMixinEmit')">
DCloud-WZF's avatar
DCloud-WZF 已提交
30 31 32
      trigger childMixinEmit
    </button>
    <MixinComp />
D
DCloud_LXH 已提交
33
    <!-- #endif -->
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  </view>
</template>

<script lang="uts">
export default {
  mixins:[{
    mixins: [{
      emits: ['childMixinEmit']
    }],
    inheritAttrs: false,
    emits:['mixinEmit']
  }],
  data(){
    return {
      rootElementTitle: '' as string | null
    }
  },
  mounted(){
雪洛's avatar
雪洛 已提交
52
    const rootElement = this.$refs['mixin-comp-root'] as UniElement
D
DCloud_LXH 已提交
53
    this.rootElementTitle = JSON.stringify(rootElement.getAttribute('title'))
DCloud-WZF's avatar
DCloud-WZF 已提交
54 55 56 57 58 59 60 61
  },
  methods: {
    triggerEmitter(emit: string){
      this.$emit(emit, emit)
    },
  }
}
</script>