How does the function in the object use this to get the current instance?
export default {
name:'calendar',
data() {
return {
moment: moment(),
month: monthArr[moment().month()],
date: moment().date(),
day: dayArr[moment().day()],
swiperOption: {
effect: 'flip',
loop: true,
onSlideNextEnd: function (swiper) {
console.log('next');
this.moment = this.moment.add(1, 'd');//这里的this不是实例的this
this.month = monthArr[this.moment.month()];
this.date = this.moment.date();
this.day = dayArr[this.moment.day()];
},
onSlidePrevEnd: function (swiper) {
console.log('prev;');
}
}
}
},
·
·
·
·
·
}
Write another computed and put swiperOption in computed. Give it a try. If you write it this way, the instance has not been created yet, so it should not be called.