export default {
data() {
return {
scrollY: 0, // 右侧滑动的Y轴坐标 (滑动过程时实时变化)
tops: [], // 所有右侧分类li的top组成的数组 (列表第一次显示后就不再变化)
food: {}, // 需要显示的food
}
},
mounted() {
this.$store.dispatch(‘getShopGoods’, () => {// 数据更新后执行
this.$nextTick(() => { // 列表数据更新显示后执行
this._initScroll()
this._initTops()
})
})
},
computed: {
…mapState([‘goods’]),
// 计算得到当前分类的下标
currentIndex() {// 初始和相关数据发生了变化
// 得到条件数据
const {scrollY, tops} = this
// 根据条件计算产生一个结果
const index = tops.findIndex((top, index) => {
// scrollY>=当前top && scrollY<下一个top
return scrollY >= top && scrollY < tops[index + 1]
})
// 返回结果
return index
}
},
methods: {
// 初始化滚动<