<div class="top"> <img src="@/assets/qiehuan_dark.png" alt="" v-if="theme == 'chalk'" @click="changetheme" /> <img src="@/assets/qiehuan_light.png" alt="" v-else @click="changetheme" /> <span>2019-01-01 00:00:00</span> </div> </div> <div class="main" ref="main"> <div class="left"> <div class="fulltrend" :class="{ full: flag1 }"> <trend class="trend" ref="trend2"> </trend> <div class="iconfont icon-expand-alt icon" @click="fullscreen1" v-if="!flag1" ></div> <div class="iconfont icon-compress-alt icon" @click="smallscreen1" v-else ></div> </div> <div class="fullseller" :class="{ full: flag }"> <seller class="seller" ref="seller2"></seller> <div class="iconfont icon-expand-alt icon" @click="fullscreen" v-if="!flag" ></div> <div class="iconfont icon-compress-alt icon" @click="smallscreen" v-else ></div> </div> </div>优化后的代码
时间: 2024-03-26 19:37:11 浏览: 181
html5_user_login.zip_:user/login.html_:user\login.html_html5 css
<div class="top">
<button class="theme-switcher" @click="changetheme">
<img :src="theme == 'chalk' ? '@/assets/qiehuan_dark.png' : '@/assets/qiehuan_light.png'" alt="">
</button>
<span>{{ currentDateTime }}</span>
</div>
<div class="main" ref="main">
<div class="left">
<div class="fulltrend" :class="{ full: flag1 }">
<trend class="trend" ref="trend2"></trend>
<button class="screen-switcher" @click="toggleFullScreen(flag1)">
<i :class="flag1 ? 'icon-compress-alt' : 'icon-expand-alt'"></i>
</button>
</div>
<div class="fullseller" :class="{ full: flag }">
<seller class="seller" ref="seller2"></seller>
<button class="screen-switcher" @click="toggleFullScreen(flag)">
<i :class="flag ? 'icon-compress-alt' : 'icon-expand-alt'"></i>
</button>
</div>
</div>
</div>
优化思路:
1. 将两个图片合并为一个按钮,通过JS控制图片的切换
2. 将日期时间通过Vue计算属性(currentDateTime)获取,避免在模板中频繁计算
3. 将两个全屏按钮合并为一个组件(screen-switcher),通过传入参数(flag1和flag)控制不同的组件状态
4. 优化CSS样式,减少不必要的代码量
阅读全文