W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
解釋: 返回一個 SelectorQuery 對象實例??梢栽谶@個實例上使用 select 等方法選擇節(jié)點,并使用 boundingClientRect 等方法選擇需要查詢的信息。
無
SelectorQuery
<view class="wrap">
<view class="card-area">
<movable-area>
<movable-view class="target" x="{{x}}" y="{{y}}" direction="all" bindchange="queryNodeInfo">
Drag
</movable-view>
</movable-area>
<view s-for="item in metrics" class="list-area border-bottom">
<text class="list-item-key-4">{{item.key}}</text>
<text class="list-item-value">{{item.val}}</text>
</view>
</view>
</view>
Page({
data: {
metrics: []
},
onReady() {
this.queryNodeInfo();
},
queryNodeInfo() {
const query = swan.createSelectorQuery();
query.select('.target').boundingClientRect();
query.exec(res => {
console.log('節(jié)點信息:', res[0]);
const rect = res[0];
if (rect) {
const metrics = []
for (const key in rect) {
if (key !== 'id' && key !== 'dataset') {
const val = rect[key];
metrics.push({key, val});
}
}
this.setData({metrics});
}
});
}
});
movable-view {
display: flex;
align-items: center;
justify-content: center;
height: 100rpx;
width: 100rpx;
background: #38f;
color: #fff;
}
movable-area {
height: 400rpx;
width: 400rpx;
background-color: #ccc;
overflow: hidden;
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: