mounted() { const timer = setInterval(() => { … }, 1000); this.$once(‘hook:beforeDestroy’, () => clearInterval(timer)😉 }
如果渲染完该页面然后进入的一个页面开启了一个定时器,最好选用上述情况
mounted() { this.timer = setInterval(() => { … }, 1000); }, beforeDestroy() { //这个是退出本页的一个函数 clearInterval(this.timer); } 如果渲染完该页面然后进入的一个页面开启了一个定时器,最好选用上述情况 <v-chart @hook:mounted=“loading = false” @hook:beforeUpdated=“loading = true” @hook:updated=“loading = false” :data=“data” /> var time=new Date().toLocaleString(‘chinese’,{hour12:false});
设施自定义属性 vue官网:https://cn.vuejs.org/v2/guide/custom-directive.html#ad directives: { //注册一个局部的自定义指令 v-focus focus: { // 指令的定义 inserted: function (el) { // 聚焦元素 el.querySelector(“input”).focus(); }, }, },
