uni-app 获取节点信息 createSelectorQuery
官网文档:https://uniapp.dcloud.net.cn/api/ui/nodes-info.html
总结一下:
适合APP端使用,且不支持nvue。
只能获取节点信息,且获取信息量有限。比如获取节点元素的高度、宽度、滚动位置等。
一、boundingClientRect 获取坐标等信息示例
// 比如元素id: formContainer uni.createSelectorQuery().select('# formContainer').boundingClientRect(data=>{ console.log(data); // 打印获取结果 }).exec()
二、选择想要获取字段信息示例:
uni.createSelectorQuery().select('#formContainer‘ ).fields({size: true,scrollOffset: true, context: true, dataset: true, id:true}, data => {
console.log("得到节点信息" + JSON.stringify(data));
console.log("width:" + data.width + ", height:" + data.height);
}).exec();