[log] vue动态的修改样式

太过爱你忘了你带给我的痛 2021-09-16 20:18 525阅读 0赞

切换背景图片

  1. <div class="carlist" :style=imgurl></div>
  2. imgurl:{ backgroundImage: "url(" + require("../../assets/nouse.png") + ")",},

切换图片

  1. <img :src=img1 />
  2. img1:require("../../assets/smartimg/right1.png"),

动态给div加边框

场景:点击地址时加上边框,并设置为当前要使用的地址

  1. <div class="c1" v-for="i in addresslist" :id=i.AddrSeq @click="checkAddress(i.AddrSeq)">
  2. </div>
  3. // 选择地址
  4. checkAddress(id) {
  5. if (this.lastel != null) {
  6. this.lastel.style.boxShadow = null
  7. }
  8. var el = document.getElementById(id)
  9. this.lastel = el;
  10. el.style.boxShadow = ' 0 2px 12px 0 #409EFF'
  11. this.currentAddress = id;
  12. },

切换class

  1. <div class="footerstyle" :class="{ 'test2':isChoose}" >
  2. </div>
  3. <style lang="scss" scoped> .footerstyle { position: absolute; bottom: 0px; width: 100%; height: 5%; background-color: #FFFFFF; display: flex; align-items: center; justify-content: center; } .test2 { background-color: #ff363d; } </style>
  4. data() {
  5. return {
  6. isChoose:false,
  7. };
  8. }
  9. methods: {
  10. changeSubmit() {
  11. this.isChoose = true
  12. },

发表评论

表情:
评论列表 (有 0 条评论,525人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Vue 动态样式绑定

    1. 简介 本小节我们将介绍 Vue 中如何动态绑定样式。包括 Class 的绑定、内联样式 Style 的绑定。掌握样式绑定的多种形式是其中的重点难点。同学们可以在学完

    相关 vue 动态样式写法

    在Vue中,可以使用动态样式来根据组件的数据或计算属性来动态地设置元素的样式。Vue提供了多种方式来实现动态样式的写法,以下是几种常见的方法: 使用:style指令: 可以