selector-query-child-multi.uvue 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<template>
  <view class="selector-query-view">
    <text>selector-query</text>
    <text class="text red">{{text1}}</text>
  </view>
  <view class="selector-query-view">
    <text>selector-query</text>
    <text class="text green">{{text2}}</text>
  </view>
  <view v-if="text1.length>0">1</view>
  <text>{{text3}}</text>
</template>

<script>
  export default {
    data() {
      return {
        text1: "",
        text2: "",
DCloud-WZF's avatar
DCloud-WZF 已提交
20 21 22
        text3: "test-text-node",
        viewCount: 0,
        selectCount: 0,
23
        selectAllCount: 0,
H
hdx 已提交
24 25
        show: false,
        testCounter: 0
26 27 28 29
      }
    },
    mounted() {
      uni.createSelectorQuery().in(this).select('.selector-query-view').boundingClientRect().exec((ret) => {
DCloud-WZF's avatar
DCloud-WZF 已提交
30 31 32
        this.text1 = JSON.stringify(ret, null, 2)
        if (ret.length == 1) {
          this.selectCount = ret.length
H
hdx 已提交
33 34 35
        }
        this.testCounter++
        this._dispatchEvent()
DCloud-WZF's avatar
DCloud-WZF 已提交
36 37 38 39 40
      })
      uni.createSelectorQuery().in(this).selectAll('.selector-query-view').boundingClientRect().exec((ret) => {
        this.text2 = JSON.stringify(ret, null, 2)
        if (ret.length == 1) {
          this.selectAllCount = (ret[0] as NodeInfo[]).length
H
hdx 已提交
41 42 43
        }
        this.testCounter++
        this._dispatchEvent()
44
      })
H
hdx 已提交
45 46 47 48 49 50 51
    },
    methods: {
      _dispatchEvent() {
        if (this.testCounter == 2) {
          uni.$emit('childReady')
        }
      }
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    }
  }
</script>

<style>
  .green {
    border: 3px solid green;
  }

  .red {
    border: 3px solid red;
  }

  .view {
    border: 3px dashed lime;
    padding: 10px;
  }

  .text {
    margin-top: 20px;
    padding: 5px;
  }
</style>