this.$nextTick(() => { setTimeout(() => { this.show = false this.$emit('close') }, 300) })
时间: 2024-05-29 11:10:44 浏览: 108
As an AI language model, I cannot determine the exact context of this code snippet. However, based on the syntax, it seems to be a Vue.js code that uses the $nextTick method to wait for the DOM to update before executing the function inside the arrow function. The setTimeout function is used to delay the execution of the code inside it by 300 milliseconds. The code inside the setTimeout function sets the value of the "show" property to false and emits a "close" event using the $emit method.
相关问题
data() { return { flag: false, flag1: false, flag2: false, flag3: false, flag4: false, flag5: false, }; }, components: { hot, seller, trend, Map, rank, stock, }, methods: { changetheme() { this.$store.commit("tabtheme"); }, full() { this.flag = true; this.$nextTick(() => { this.$refs.seller2.changesize(); }); }, full1() { this.flag1 = true; this.$nextTick(() => { this.$refs.trend2.screenAdapter(); }); }, full2() { this.flag2 = true; this.$nextTick(() => { this.$refs.rank2.screenAdapter(); }); }, full3() { this.flag3 = true; this.$nextTick(() => { this.$refs.hot2.screenAdapter(); }); }, full4() { this.flag4 = true; this.$nextTick(() => { this.$refs.stock2.screenAdapter(); }); }, full5() { this.flag5 = true; this.$nextTick(() => { this.$refs.map2.screenAdapter(); }); },优化后代码
data() {
return {
flags: [false, false, false, false, false, false],
};
},
components: {
hot,
seller,
trend,
Map,
rank,
stock,
},
methods: {
changetheme() {
this.$store.commit("tabtheme");
},
full(index) {
this.flags[index] = true;
this.$nextTick(() => {
switch (index) {
case 0:
this.$refs.seller2.changesize();
break;
case 1:
this.$refs.trend2.screenAdapter();
break;
case 2:
this.$refs.rank2.screenAdapter();
break;
case 3:
this.$refs.hot2.screenAdapter();
break;
case 4:
this.$refs.stock2.screenAdapter();
break;
case 5:
this.$refs.map2.screenAdapter();
break;
default:
break;
}
});
},
},
<div class="fullseller" :class="{ full: flag }"> <seller class="seller" ref="seller2"></seller> <div class="iconfont icon-expand-alt icon" @click="full" v-if="!flag" ></div><div class="fullmap" :class="{ full: flag5 }"> <Map class="map" ref="map2"></Map> <div class="iconfont icon-expand-alt icon" @click="full5" v-if="!flag5" ></div>data() { return { flag: false, flag1: false, flag2: false, flag3: false, flag4: false, flag5: false, }; }, components: { hot, seller, trend, Map, rank, stock, },small() { this.flag = false; this.$nextTick(() => { this.$refs.seller2.changesize(); }); }, small1() { this.flag1 = false; this.$nextTick(() => { this.$refs.trend2.screenAdapter(); }); }, small2() { this.flag2 = false; this.$nextTick(() => { this.$refs.rank2.screenAdapter(); }); }, small3() { this.flag3 = false; this.$nextTick(() => { this.$refs.hot2.screenAdapter(); }); }, small4() { this.flag4 = false; this.$nextTick(() => { this.$refs.stock2.screenAdapter(); }); }, small5() { this.flag5 = false; this.$nextTick(() => { this.$refs.map2.screenAdapter(); });优化后代码
<div class="fullseller" :class="{ full: flag }">
<seller class="seller" ref="seller2"></seller>
<div class="iconfont icon-expand-alt icon" @click="full" v-if="!flag" ></div>
</div>
<div class="fullmap" :class="{ full: flag5 }">
<Map class="map" ref="map2"></Map>
<div class="iconfont icon-expand-alt icon" @click="full5" v-if="!flag5" ></div>
</div>
data() {
return {
flag: false,
flag5: false,
};
},
components: {
seller,
Map,
},
methods: {
full() {
this.flag = !this.flag;
this.$nextTick(() => {
this.$refs.seller2.changesize();
});
},
full5() {
this.flag5 = !this.flag5;
this.$nextTick(() => {
this.$refs.map2.screenAdapter();
});
},
}
阅读全文