From 774a5f32f8dd98db3f31fd0db91ed7f53c7231ef Mon Sep 17 00:00:00 2001 From: YangFong Date: Wed, 10 Aug 2022 13:30:07 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=8E=BB=E9=99=A4=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E5=8F=98=E9=87=8F=20=5Fthis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据箭头函数特点,直接使用 this,无需创建临时变量 --- src/layout/components/tags.vue | 35 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/layout/components/tags.vue b/src/layout/components/tags.vue index 29a986e3..ae23c706 100644 --- a/src/layout/components/tags.vue +++ b/src/layout/components/tags.vue @@ -65,17 +65,16 @@ }) }, contextMenuVisible(value) { - var _this = this; - var cm = function(e){ - let sp = document.getElementById("contextmenu"); - if(sp&&!sp.contains(e.target)){ - _this.closeMenu() + const cm = (e) => { + const sp = document.getElementById("contextmenu"); + if (sp && !sp.contains(e.target)) { + this.closeMenu() } } if (value) { - document.body.addEventListener('click', e=>cm(e)) - }else{ - document.body.removeEventListener('click', e=>cm(e)) + document.body.addEventListener('click', e => cm(e)) + } else { + document.body.removeEventListener('click', e => cm(e)) } } }, @@ -160,24 +159,24 @@ this.contextMenuVisible = false }, //TAB 刷新 - refreshTab(){ - var nowTag = this.contextMenuItem; + refreshTab() { this.contextMenuVisible = false + const nowTag = this.contextMenuItem; //判断是否当前路由,否的话跳转 - if(this.$route.fullPath != nowTag.fullPath){ + if (this.$route.fullPath !== nowTag.fullPath) { this.$router.push({ path: nowTag.fullPath, query: nowTag.query }) } + this.$store.commit("refreshIframe", nowTag) - var _this = this; - setTimeout(function() { - _this.$store.commit("removeKeepLive", nowTag.name) - _this.$store.commit("setRouteShow", false) - _this.$nextTick(() => { - _this.$store.commit("pushKeepLive",nowTag.name) - _this.$store.commit("setRouteShow", true) + setTimeout(() => { + this.$store.commit("removeKeepLive", nowTag.name) + this.$store.commit("setRouteShow", false) + this.$nextTick(() => { + this.$store.commit("pushKeepLive", nowTag.name) + this.$store.commit("setRouteShow", true) }) }, 0); },