<div class="fullhot" :class="{ full: flag4 }"> <hot class="hot" ref="hot2"></hot> <div class="iconfont icon-expand-alt icon" @click="fullscreen4" v-if="!flag4" ></div> <div class="iconfont icon-compress-alt icon" @click="smallscreen4" v-else ></div><div class="fullstock" :class="{ full: flag5 }"> <stock class="stock" ref="stock2"></stock> <div class="iconfont icon-expand-alt icon" @click="fullscreen5" v-if="!flag5" ></div> <div class="iconfont icon-compress-alt icon" @click="smallscreen5" v-else ></div>data() { return { flag1: false, flag2: false, flag3: false, flag4: false, flag5: false, flag6: false, }; }, components: { hot, seller, trend, Map, rank, stock, }, methods: { changetheme() { this.$store.commit("tabtheme"); }, fullscreen1() { this.flag = true; this.$nextTick(() => { this.$refs.seller2.changesize(); }); }, fullscreen2() { this.flag1 = true; this.$nextTick(() => { this.$refs.trend2.screenAdapter(); }); }, fullscreen3() { this.flag2 = true; this.$nextTick(() => { this.$refs.rank2.screenAdapter(); }); }, fullscreen4() { this.flag3 = true; this.$nextTick(() => { this.$refs.hot2.screenAdapter(); }); }, fullscreen5() { this.flag4 = true; this.$nextTick(() => { this.$refs.stock2.screenAdapter(); }); }, fullscreen6() { this.flag5 = true; this.$nextTick(() => { this.$refs.map2.screenAdapter(); }); },优化后代码
时间: 2024-03-26 21:36:03 浏览: 22
<div class="fullhot" :class="{ full: flag4 }">
<hot class="hot" ref="hot2"></hot>
<div class="iconfont icon-expand-alt icon" @click="fullscreen4" v-if="!flag4"></div>
<div class="iconfont icon-compress-alt icon" @click="smallscreen4" v-else></div>
</div>
<div class="fullstock" :class="{ full: flag5 }">
<stock class="stock" ref="stock2"></stock>
<div class="iconfont icon-expand-alt icon" @click="fullscreen5" v-if="!flag5"></div>
<div class="iconfont icon-compress-alt icon" @click="smallscreen5" v-else></div>
</div>
data() {
return {
flags: [false, false, false, false, false, false],
};
},
components: {
hot,
seller,
trend,
Map,
rank,
stock,
},
methods: {
changetheme() {
this.$store.commit("tabtheme");
},
fullscreen(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;
}
});
},
smallscreen(index) {
this.flags[index] = false;
},
},
```
优化后的代码将重复的部分整合为一个函数,并使用一个数组来存储每个组件的状态。同时,使用了 switch 语句来区分不同的组件,提高了代码的可读性和可维护性。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
請你幫我打修改HTML代碼<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>异常记录</title> <style> .main { display: flex; flex-direction: row; justify-content: space-between; align-items: center; } </style> </head> <body> 首页 登记数据 查询数据 异常记录登记 <form method="post" action="/submit"> <label>确认线别:</label> <input type="text" name="line">
<label>确认日期:</label> <input type="date" name="date">
<label>异常机种:</label> <input type="text" name="model">
<label>异常现象:</label> <textarea name="issue"></textarea>
<label>生产日期:</label> <input type="date" name="prod_date">
<label>生产班别:</label> <input type="text" name="shift">
<label>生产线别:</label> <input type="text" name="prod_line">
<label>责任人:</label> <input type="text" name="responsible">
<input type="submit" value="提交"> </form> 欢迎访问 </body> </html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)