您当前的位置: 首页 > 

小志的博客

暂无认证

  • 2浏览

    0关注

    1217博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Vue——class与style绑定

小志的博客 发布时间:2019-09-01 22:25:03 ,浏览量:2

1、代码如下:




  
  class与style绑定
  
    .classA {
      color: red;
    }
    .classB {
      background: blue;
    }
    .classC {
      font-size: 20px;
    }
  






  1. class绑定: :class='xxx'
  xxx是字符串
  xxx是对象
  xxx是数组

  2. style绑定
  :style="{ color: activeColor, fontSize: fontSize + 'px' }"

  更新





  new Vue({
    el: '#demo',
    data: {
      myClass: 'classA',
      hasClassA: true,
      hasClassB: false,
      activeColor: 'red',
      fontSize: '20px'
    },

    methods: {
      update () {
        this.myClass = 'classB'
        this.hasClassA = !this.hasClassA
        this.hasClassB = !this.hasClassB
        this.activeColor = 'yellow'
        this.fontSize = '30px'
      }
    }
  })



2、效果图如下: 1)初始页面效果图: 在这里插入图片描述 2)点击更新之后的效果图: 在这里插入图片描述

关注
打赏
1661269038
查看更多评论
立即登录/注册

微信扫码登录

0.0431s