动态绑定样式(三元表达式 动态添加类)

<template>
  <div>
    <div :class="[isflag? 'boxone' : 'boxtwo']">测试1</div>
    <button @click="isflag=!isflag">按钮</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      isflag:true,
    };
  },
};
</script>
<style lang="scss" scoped>
.boxone{
  width: 200px;
  height: 200px;
  background-color: yellow;
}
.boxtwo{
  width: 200px;
  height: 200px;
  background-color: red;
}
</style>

猜你喜欢

转载自blog.csdn.net/Frazier1995/article/details/120562975