1.定义公共方法
export default{
getRect(selector){
return new Promise((resolve) => {
let view = uni.createSelectorQuery().select(selector);
view.fields({
size: true,
rect: true,
scrollOffset:true
}, (res) => {
resolve(res);
}).exec();
})
}
}
2.main.js中引入
import Vue from 'vue'
import App from './App'
import Tool from './utils/Tool.js'
Vue.prototype.$Tool = Tool
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
3.页面调用
onShow(){
this.$Tool.getRect(".className").then(res => {
console.log(res)
})
},