vue 页面定时发送请求刷新数据

在页面中这样写

motheds:{

    getListIng() {

        // 这里是一个http的异步请求

        if (this.$route.path == '当前路由' ) { 

           

this.getData() //请求的函数

let _this = this;

console.log('定时请求-----------')

            this.timeOut = setTimeout(() => {

                _this.getListIng();

扫描二维码关注公众号,回复: 4745599 查看本文章

            }, 5000);

        } else {

            this.timeOut = '';

        }

    },

}

created() {

    if ( this.timeOut ) {

        clearTimeout(this.timeOut);

    }

    this.getListIng();

},

computed: {

    timeOut: {

        set (val) {

            this.$store.state.timeout.compileTimeout = val; //记得在全局中定义一下

        },

        get() {

            return this.$store.state.timeout.compileTimeout;

        }

    },

}

猜你喜欢

转载自blog.csdn.net/jiuweiyaoy/article/details/85600839