Vue.js 中 computed 属性依赖的 count 为 0 的问题解决方法
根据提供的代码,可能是因为 getList 方法是异步请求数据,而 created 方法中调用 getList 方法是同步的,所以在调用 pageCount 时,count 还没有被赋值。可以尝试在 getList 方法中将 count 赋值为 0,然后在请求成功后再赋值为实际值,这样在调用 pageCount 时就不会为 0 了。例如:
getList() {
this.count = 0 // 先将 count 赋值为 0
let data = {
category_id: this.type,
page: this.currentPage,
limit: 4
}
getOpus(data).then(res => {
if (res.code == 200) {
this.list = res.data.list
this.count = res.data.count // 请求成功后再赋值为实际值
}
})
}
原文地址: https://www.cveoy.top/t/topic/ofS7 著作权归作者所有。请勿转载和采集!