maioyan
maioyan copied to clipboard
keep-alive小性能优化~
对于keep-alive
需要使用activated
来代替mounted
来重新加载数据
data() {
return {
allCity: [], // 存放城市数据
isLoading: true,
cityId: -1 // 优化ID
};
},
activated() {
// console.log('ok')
let cityId = this.$store.state.city.id;
if (this.cityId === cityId) return;
this.isLoading = true;
this.axios.get("/api/cinemaList?cityId=" + cityId).then(res => {
// console.log(res)
// 判断数据是否请求成功
if (res.status === 200) {
// 将数据赋值到存放的数据数组中
this.allCity = res.data.data.cinemas;
this.cityId = cityId;
this.isLoading = false;
}
});
},