this.$nextTick().html 页面数据刷新完以后,再执行回调函数中的方法

var vm = new Vue({
el:'#app',
data:{msg:'小明'},
methods: {
change(){
this.msg='小绿'
console.log(document.getElementById('p1').innerText); //小明,因为this.msg是异步的
 
}
},
 
});
 
解决方式
 
var vm = new Vue({
el:'#app',
data:{msg:'小明'},
methods: {
change(){
this.msg='小绿'
this.$nextTick(()=>{
console.log(document.getElementById('p1').innerText); //小明
})
 
}
},
 
});
 
 

猜你喜欢

转载自www.cnblogs.com/xiannv/p/10993439.html
今日推荐