今天在完善仿卖座移动端项目的时候,因为获取影院的ajax在actions里面定义,因为数据量大,所以使用了better-scroll
之前是因为在影院组件里面直接写的ajax,所以$nextTick出现了判断的错误,如果变换了ajax的获取,它会存留上一次的最后的状态
所以我用了一个比较笨的办法,将组件里面的this直接传给state里面定义的一个变量,然后使用这个变量再调用$nextTick
state: {
vuethis: null
},
mutations: {
//获取this
getVuethis(state, loop) {
state.vuethis = loop
}
},
actions: {
GetCinemas(store) {
Indicator.open({
text: '加载中...',
spinnerType: 'fading-circle'
});
axios({
url: `https://m.maizuo.com/gateway?cityId=${
store.state.cityID}&ticketFlag=1&k=1573618`,
methods: 'get',
headers: {
'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"15656848532164663517222"}',
'X-Host': 'mall.film-ticket.cinema.list'
}
}).then((res) => {
store.state.CinemaData = res.data.data.cinemas
Indicator.close();
//这里调用
store.state.vuethis.$nextTick(() => {
new BScroll('.cinemas-scroll', {
scrollY: true,
scrollbar: true,
});
})
})
}
}
就可以正常使用了。如果还有更好的方式欢迎指出。。