在uni app项目中 获取手机屏幕可用高度 动态设置盒子高度时
export default {
data() {
return {
//手机可用高度
_height: 0,
};
},
onLoad: function(res) {
that = this
util._getMobileHeight(res => {
console.log(res)
that._height = res.windowHeight
})
},
methods: {
}
}
这样其实没有问题 在H5都能设置成功,但在小程序里 data的值却没有更改成功
可能是我这菜鸡见识少,找了许久没有解决办法,后来突然想到试试往里面放点内容看看能不能赋值成功,结果成功了,代码改成这样
export default {
data() {
return {
//手机可用高度
_height: 0,
mas:null
};
},
onLoad: function(res) {
that = this
util._getMobileHeight(res => {
console.log(res)
that._height = res.windowHeight
that.mas = 'hello'
})
},
methods: {
}
}
就可以了 ,哎。。。。。。倒霉催的