nodes-info.uvue 2.1 KB
Newer Older
H
hdx 已提交
1 2 3 4 5 6 7 8 9 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
<template>
  <view>
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap uni-common-mt">
      <button @click="getNodeInfo">getNodeInfo</button>
    </view>
    <view class="rect" :style="{left: left, width: width, height: height}"></view>
    <view class="rect-info">
      <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>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        title: 'createSelectorQuery',
        nodeInfo: { left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0 } as NodeInfo,
        left: 16,
        width: 150,
        height: 100,
      }
    },
    methods: {
      getNodeInfo() {
        uni.createSelectorQuery().select('.rect').boundingClientRect().exec((ret) => {
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
51
          this.nodeInfo = ret[0] as NodeInfo
H
hdx 已提交
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
        })
      }
    }
  }
</script>

<style>
  .rect {
    background-color: dodgerblue;
    margin-top: 50px;
  }

  .rect-info {
    display: flex;
    flex-direction: column;
    padding: 15px;
  }

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

  .node-info-item-k {
    width: 100px;
    line-height: 24px;
  }

  .node-info-item-v {
    font-weight: bold;
    line-height: 24px;
  }
</style>