This is the initial value passed in. Every time the page is loaded, the value will be fetched from the local storage. If there is any, it will be passed in directly. At the same time, it will go to the server to request news information, update this.news, and then restart Passing in the new value of the swipe component will not trigger the update of the dom, and the carousel pictures will remain the same. Why is this? The console prints out that the incoming news value has indeed changed. Shouldn't it trigger an update to the DOM in a responsive manner?
data(){
return{
news:localStorage.getItem("news")
}
}
getSwipePictrue:function(){
this.axios.post("News.php").then((res)=>{
if(res.data.errCode=='1'){
_this.news=JSON.stringify(res.data.news)
localStorage.setItem('news',JSON.stringify(res.data.news))
}
})
}
Suddenly I found that the DOM was updated, but the Swipe plug-in was not running normally.
I keep solving problems that I don’t have, and I’m drunk.
在swiper的配置中加入observer:true,observeParents:true。开启观察者模式,会动态监听你的swiper的变化的。详细参考api。一个有信仰的程序员,Notonce。
_this 哪里试试 var _this = this;
尝试在 swipe 组件中监听异步获取的数据
this.swipe 作为 swipe 组件的真实数据
遇到了同样的问题,我的问题是往后切换data数据更新dom会跟着更新,当向前切换时只有最后一个swiper-slide的dom的index是0,其他的是正常的,很神奇!查看vue的data是更新了的;但在dom里打出来就是0;
![图片上传中...]
![](http://img.php.cn/upload/image/000/000/000/0217674c2d4f7b81a196fb9bfdce83dd-0.png)