zoukankan      html  css  js  c++  java
  • Vue中监听数据是否渲染完成,完成后执行相关方法

    var vm = new Vue({
        data: { list: [] },
        methods: {
            changeDom: function () {
                this.$nextTick(function(){
                    //需要执行的方法
                });
            }
        },
        watch: {
            list: function () {
                this.$nextTick(function(){
                    //需要执行的方法
                });
            }
        }
    })

    如下应用示例(有一个滚动事件,必须要页面渲染完成后才可以执行):

    var vue2 = new Vue({
            el: "#vueNotice",
            data: { list: [] },
            mounted: function () {
                this.newlyData();
            },        
            methods: {
                newlyData() {
                    var self = this;
                    ajaxPureRequest('/sales/GetNewly', 'get', null, false, function (rs) {
                        if (rs.code == "200") {
                            self.list = rs.res.data;
                            if (rs.res.data.length==0) {
                                $("#notice").css("display", "none");
                            }                            
                        }
                    });
                  
                }
            },
            watch: {
                list: function () {
                    this.$nextTick(function () {
                        $('#notice').rollSlide({
                            orientation: 'top',
                            num: 1,
                            v: 2500,
                            isRoll: true
                        });
                    })
                }           
            },
        });
    学习交流群:364976091
  • 相关阅读:
    python函数及模块
    Python分支结构及循环结构
    python基本的知识
    11.21学习总结
    进度日报28
    进度日报27
    进度日报26
    进度日报25
    进度日报24
    11.14学习总结
  • 原文地址:https://www.cnblogs.com/firstcsharp/p/15097436.html
Copyright © 2011-2022 走看看