firstLeft: function () {
var _self = this;
if (_self.computed) {
return $(".ButtonsBS").eq(0).offset().left;
}
},
lastRight: function () {
var _self = this;
if (_self.computed) {
var _tem = $(".ButtonsBS").length;
return $(".ButtonsBS").eq(_tem - 1).offset().left + $(".ButtonsBS").eq(_tem - 1).outerWidth();
}
},
buttonArealeft: function () {
var _self = this;
if (_self.computed) {
return $("#Button-Area__really").offset().left;
}
},
buttonArearight: function () {
if (this.computed) {
return $("#Button-Area__really").offset().left + $("#Button-Area__really").outerWidth();
}
},
needLeft: function () {
if (this.computed) {
var _self = this;
return _self.firstLeft < _self.buttonArealeft;
}
},
needRight: function () {
if (this.computed) {
var _self = this;
return _self.lastRight > _self.buttonArearight;
}
}
如上代码:
问题1:
VUE computed 里面写了关于DOM的操作,一来就报错,所以是不是computed的时候,DOM还没有渲染是吧?
所以,我
加了一个判断,就是那个computed,只有在mounted的时候,才为true
问题2:
我的DOM元素移动的时候,按理来说computed是一直监听我所需要computed元素里面所带参数的变化呀,比如
$(".ButtonsBS").eq(0).offset().left
但是 我发现computed计算完之后就没有变过【事实是那个元素一直在移动。。。不可能不变】。。。。所以问了一个这个问题
VUE computed 是不是不能监听DOM长宽高以及Offset的变化啊?
vue react 的一些理念里 就是希望数据驱动 可以尝试改变代码的思路
数据驱动的话 vue 里比较关键的一些属性 computed watch $nextTick 应该可以解决你的问题