methods: {
// 下拉刷新回调
pullupRefresh () {
var _this = this
setTimeout(function () {
_this.add()
// 停止刷新
_this.mui('#pullrefresh').pullRefresh().endPulldownToRefresh()
}, 1500)
},
pulldownRefresh () {
var _this = this
setTimeout(function () {
_this.mui('#pullrefresh').pullRefresh().endPullupToRefresh(_this.count >= _this.isNumber)
_this.add()
// 小于数据的长度 提示
if (_this.count <= Math.floor(_this.chartList.length / 5)) {
_this.mui.toast("为你推荐了5篇文章")
}
}, 1500);
},
add () {
this.count += 1
// 截取5个数据
this.newArr = this.chartList.slice((this.count - 1) * 5, (this.count - 1) * 5 + 5)
var box = document.getElementById("pullName")
// 获取box的style属性用作判断
var styleList = window.getComputedStyle(box)
console.log(this.count, 4455)
if (this.count <= 10/5) {
// 首次加载10条数据
this.arr = this.chartList.slice(0, 10)
} else if (styleList.transform.indexOf('50') !== -1) {
// 下拉执行向数组头部添加
this.arr.unshift.apply(this.arr, this.newArr)
} else {
// 上拉加载向数组后面添加
this.arr.push.apply(this.arr, this.newArr)
}
this.isNumber = Math.floor(this.chartList.length / 5)
}
}
}
上面的使用vue+mui的有的时候this指向会发生变化,但是不想用var _this = this来把全局赋给一个变量,
有没有其他方法!我用过Window,document,不行!!
不用
that = this
的话,最好的方法就用bind
了,understanding-javascript-function-prototype-bind
可以参考下这种写法 把setTimeout 里面的函数提出来: