在onLoad()里面已经将windowWidth保存到data中,在滚动事件的代码中写代码,war width=this.data.windowWidth,却报错提示,类型{}上不存在属性”windowWidth“.如果在滚动事件代码中把onLoad中的代码:var systemInfo = systemInfo.windowWidth var windowWidth = systemInfo.widowWidth;var width = windowWidth,写进去,就不会报这样的错,这是生命原因?如果多个地方需要用到这个属性,那不是每次都得重新写一遍?
onLoad() {
var systemInfo=wx.getSystemInfoSync();
var windowHeight = systemInfo.windowHeight;
var windowWidth = systemInfo.windowWidth;
var width = windowWidth;
var height = 100;
var radius = (height/2)+(width*width/8/height);
var left = -(radius-width/2);
this.setData({
windowHeight:windowHeight,
windowWidth:windowWidth,
radius:radius,
left:left
})
},
/**
* 滚动的事件
*/
scrollEvent:function(event:any){
var scrollTop = event.detail.scrollTop;
if(scrollTop > 0 && scrollTop <= 100){
var height = 100-scrollTop;
var width = this.data.windowWidth;
// var systemInfo=wx.getSystemInfoSync();
// var windowWidth = systemInfo.windowWidth;
// var width = windowWidth;
var radius = (height/2)+(width*width/8/height);
var left = -(radius-width/2);
this.setData({
radius:radius,
left:left
})
}
},