axios
.get('/user?ID=12345')
.then(function (response) {
// 获取数据更新
this.imgList = response;
// DOM还没有更新
this.$nextTick(() => {
// DOM更新了
// swiper重新初始化
/* eslint-disable no-new */
new Swiper('.swiper-container', {})
})
})
.catch(function (error) {
console.log(error);
});
到此,轮播图的效果实现了。
总结
swiper是我们平时很常用的插件,但将swiper导入vue项目中遇到的问题不少。最主要的问题是要搞懂vue的生命周期,这样才能有效地使用各种js插件。










