• 【VUE】Class 与 Style 绑定


    官方链接

    Class 与 Style 绑定 — Vue.js
    https://cn.vuejs.org/v2/guide/class-and-style.html

    笔记例子

    效果图

    代码

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset="UTF-8" />
      <title></title>
      <script src="vue.js"></script>
      <style>
        .red {
          color: red;
        }
    
        .fontBig {
          font-size: larger;
        }
      </style>
    </head>
    
    <body>
      <div id="vueApp">
        <div :class="{red:isRed}" @click="clickDiv1">
          class绑定对象写法 :class="{类名1:真假,类名2:真假}"
        </div>
        <div :class="[{red:isRed},fontClassName]" @click="clickDiv2">
          class绑定数组写法 :class="[对象,class名变量]"
        </div>
        <div :style="{fontSize:fontSizeName,color:colorName}" @click="clickDiv3">
          style绑定对象写法 :style="JS对象"
        </div>
        <div :style="[baseStyleObj,colorStyleObj]">
          style绑定数组写法 :style="[JS对象1,JS对象2]"
        </div>
      </div>
    </body>
    <script>
      //初始化VUE页面
      var vm = new Vue({
        el: "#vueApp",
        data: {
          isRed: false,
          fontClassName: "fontBig",
          colorName: "black",
          fontSizeName: "small",
          baseStyleObj: {
            fontSize: "small",
          },
          colorStyleObj: {
            color: "red",
          }
        },
        watch: {
          fontSizeName: function (val) {
            this.baseStyleObj.fontSize = this.fontSizeName;
          },
          colorName: function (val) {
            this.colorStyleObj.color = this.colorName;
          }
    
        },
        methods: {
          clickDiv1: function () {
            this.isRed = !this.isRed;
          },
          clickDiv2: function () {
            this.isRed = !this.isRed;
          },
          clickDiv3: function () {
            if (this.colorName === "black") {
              this.colorName = "red";
            } else {
              this.colorName = "black";
            }
    
            if (this.fontSizeName === "small") {
              this.fontSizeName = "larger";
            } else {
              this.fontSizeName = "small";
            }
          }
        }
      });
    </script>
    
    </html>
  • 相关阅读:
    C# DateTimePicker控件详解
    python2.7虚拟环境virtualenv安装及使用
    Python2.7 安装numpy报错解决方法
    关于C语言中递归的一点点小问题
    Drozer--AndroidApp安全评估工具
    Android--native层so文件调试
    New Blog
    小旭讲解 LeetCode 53. Maximum Subarray 动态规划 分治策略
    2017年度回忆与总结 – 心态
    基于文本图形(ncurses)的文本搜索工具 ncgrep
  • 原文地址:https://www.cnblogs.com/chang-an/p/12329185.html
Copyright © 2020-2023  润新知