Vue.$nextTick&Vue.nextTick

  • Vue.nextTick(callback),当数据发生变化,更新后执行回调。
  • Vue.$nextTick(callback),当dom发生变化,更新后执行的回调。
    参考&实例
实例:

<ul id="demo">
    <li v-for="item in list">{{item}}</div>
</ul>

new Vue({
    el:'#demo',
    data:{
        list=[0,1,2,3,4,5,6,7,8,9,10]
    },
    methods:{
        push:function(){
            this.list.push(11);
            this.nextTick(function(){
                alert('数据已经更新')
            });
            this.$nextTick(function(){
                alert('v-for渲染已经完成')
            })
        }
    }})
或者:

this.$http.post(apiUrl)
    .then((response) => {
    if (response.data.success) {
        this.topFocus.data = response.data.data;
        this.$nextTick(function(){
                    //渲染完毕
        });
        }
    }).catch(function(response) {
        console.log(response);
    });

猜你喜欢

转载自blog.csdn.net/Lpandeng/article/details/80547588
今日推荐