<view ref="st"></view>
this.$refs.st.$el.style.background="#fff"
console.log(this.$refs.st.$el.style.background)
//微信小程序里面 获取dom ,ref微信小程序用不了
export const SelectorQuery = (id, that) => {
return new Promise((resolve, reject) => {
let query = uni.createSelectorQuery().in(that).select(id).boundingClientRect(function(data) {
resolve(JSON.stringify(data))
}).exec();
})
}
//按需引入
import {
SelectorQuery
} from "@/api/index.js"
//使用
async onLoad() {
console.log( await SelectorQuery(".content",this))
},
//或者在页面直接用
onLoad() {
this.$nextTick( () => {
let query = uni.createSelectorQuery().select('#first').boundingClientRect(function(data) {
console.log(1,data)
}).exec();
})
// this.$nextTick( () => {
// //必须先创建SelectorQuery对象的实例,该实例用来查询DOM节点的信息
// const query = uni.createSelectorQuery()
// //匹配选择器的第一个节点,selectAll匹配选择器的所有节点
// query.select('#first').boundingClientRect( rect => {
// //rect是包含元素大小、位置等数据的对象
// console.log(2,rect)
// }).exec(() => {
// //节点信息获取成功后执行的回调函数
// })
// })
}