nodes-info.uvue 2.8 KB
Newer Older
H
hdx 已提交
1
<template>
2
  <view class="uni-padding-wrap">
H
hdx 已提交
3
    <page-head :title="title"></page-head>
4 5 6 7 8
    <button class="btn btn-get-node-info" @click="getNodeInfo">getNodeInfo</button>
    <button class="btn btn-get-all-node-info" @click="getAllNodeInfo">getAllNodeInfo</button>
    <view class="rect-1-2">
      <view class="rect rect1"></view>
      <view class="rect rect2"></view>
H
hdx 已提交
9
    </view>
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    <view class="rect-info-1-2">
      <view class="rect-info" v-for="(nodeInfo, index) in nodeInfoList" :key="index">
        <view class="node-info-item">
          <text class="node-info-item-k">left: </text>
          <text class="node-info-item-v">{{nodeInfo.left}}</text>
        </view>
        <view class="node-info-item">
          <text class="node-info-item-k">top: </text>
          <text class="node-info-item-v">{{nodeInfo.top}}</text>
        </view>
        <view class="node-info-item">
          <text class="node-info-item-k">right: </text>
          <text class="node-info-item-v">{{nodeInfo.right}}</text>
        </view>
        <view class="node-info-item">
          <text class="node-info-item-k">bottom: </text>
          <text class="node-info-item-v">{{nodeInfo.bottom}}</text>
        </view>
        <view class="node-info-item">
          <text class="node-info-item-k">width: </text>
          <text class="node-info-item-v">{{nodeInfo.width}}</text>
        </view>
        <view class="node-info-item">
          <text class="node-info-item-k">height: </text>
          <text class="node-info-item-v">{{nodeInfo.height}}</text>
        </view>
H
hdx 已提交
36 37 38 39 40 41 42 43 44 45
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        title: 'createSelectorQuery',
46
        nodeInfoList: [] as NodeInfo[],
H
hdx 已提交
47 48 49 50
      }
    },
    methods: {
      getNodeInfo() {
51 52 53 54 55 56 57 58 59
        uni.createSelectorQuery().select('.rect1').boundingClientRect().exec((ret) => {
          this.nodeInfoList.length = 0
          this.nodeInfoList.push(ret[0] as NodeInfo)
        })
      },
      getAllNodeInfo() {
        uni.createSelectorQuery().selectAll('.rect').boundingClientRect().exec((ret) => {
          this.nodeInfoList.length = 0
          this.nodeInfoList.push(...(ret[0] as NodeInfo[]))
H
hdx 已提交
60 61 62 63 64 65 66
        })
      }
    }
  }
</script>

<style>
67 68 69 70 71 72 73 74 75
  .btn {
    margin-top: 15px;
  }

  .rect-1-2 {
    flex-direction: row;
    margin-top: 15px;
  }

H
hdx 已提交
76
  .rect {
77 78 79 80 81
    width: 150px;
    height: 100px;
  }

  .rect1 {
H
hdx 已提交
82
    background-color: dodgerblue;
83 84 85 86 87 88 89 90 91 92
  }

  .rect2 {
    margin-left: auto;
    background-color: seagreen;
  }

  .rect-info-1-2 {
    flex-direction: row;
    margin-top: 15px;
H
hdx 已提交
93 94 95
  }

  .rect-info {
96
    flex: 1;
H
hdx 已提交
97 98 99 100 101 102 103 104
    flex-direction: column;
  }

  .node-info-item {
    flex-direction: row;
  }

  .node-info-item-k {
105 106
    width: 72px;
    line-height: 2;
H
hdx 已提交
107 108 109 110
  }

  .node-info-item-v {
    font-weight: bold;
111
    line-height: 2;
H
hdx 已提交
112 113
  }
</style>