首页 > 其他分享 >040 Dynamic Classes Array Syntax

040 Dynamic Classes Array Syntax

时间:2024-08-22 20:28:41浏览次数:7  
标签:box color boxBSelected Dynamic Classes boxASelected margin Array border

示例

index.html

:class="['demo',{active: boxBSelected}]"

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vue Basics</title>
    <link
      href="https://fonts.googleapis.com/css2?family=Jost:wght@400;700&display=swap"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="styles.css" />
    <script src="https://unpkg.com/vue@3/dist/vue.global.js" defer></script>
    <script src="app.js" defer></script>
  </head>
  <body>
    <header>
      <h1>Vue Dynamic Styling</h1>
    </header>
    <section id="styling">
      <div class="demo" :class="boxAClasses" @click="boxSelected('A')"></div>
      <!-- <div class="demo" :class="{active: boxBSelected}" @click="boxSelected('B')"></div> -->
      <div :class="['demo',{active: boxBSelected}]" @click="boxSelected('B')"></div>
      <div class="demo" :class="{active: boxCSelected}" @click="boxSelected('C')"></div>
    </section>
  </body>
</html>

app.js

const app = Vue.createApp({
    data(){
        return {
            boxASelected: false,
            boxBSelected: false,
            boxCSelected: false,
        };
    },
    computed: {
        boxAClasses() {
            return {active: this.boxASelected};
        }
    },
    methods:{
        boxSelected(box){
            if (box === 'A'){
                this.boxASelected = !this.boxASelected;
            }else if (box === 'B'){
                this.boxBSelected = !this.boxBSelected;
            }else if (box === 'C'){
                this.boxCSelected = !this.boxCSelected;
            }
        }
    }
});

app.mount('#styling');

styles.css

* {
  box-sizing: border-box;
}

html {
  font-family: 'Jost', sans-serif;
}

body {
  margin: 0;
}

header {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  margin: 3rem;
  border-radius: 10px;
  padding: 1rem;
  background-color: #4fc08d;
  color: white;
  text-align: center;
}

#styling {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
  margin: 3rem;
  border-radius: 10px;
  padding: 1rem;
  text-align: center;
}

.demo {
  width: calc(100% - 32px);
  height: 100px;
  margin: 16px;
  border: 2px dashed #ccc;
}

.active { 
  border-color: red;
  background-color: salmon;
}

标签:box,color,boxBSelected,Dynamic,Classes,boxASelected,margin,Array,border
From: https://blog.csdn.net/KevinHuang2088/article/details/141437106

相关文章

  • SPONGE进阶教程:MetaDynamics的简单用例
    前序课程1前序课程2场景简述蛋白与配体对接后,采用通常的分子动力学模拟,通常会采样得到势阱附近的大量结构(如下图左L-P),即蛋白-配体结合构象的平均系综。如果想要探究蛋白-配体解离过程,需要克服一个解离能垒,去到L-P*,甚至更远的L+P解离状态。这时候静候模拟体系自然地运动过去是不......
  • ArrayDeque源码解读
    ArrayDequeArrayDeque和LinkedList是Deque的两个通用实现,在使用Queue时,由于Queue只是一个接口,因此创建Queue时也会使用ArrayDeque为了实现在数组两端进行操作元素的需求,因此ArrayDeque使用循环数组作为底层数据结构,同时,ArrayDeque中定义了head和tail两个指针指向头和尾因为是循......
  • 关于Arrays.asList返回List无法新增和删除?
    关于Arrays.asList返回的List无法新增和删除?这个是在写项目的时候发现的,然后就分析了一下源码,得其内部原理复现代码示例:publicclassArraysAsList{publicstaticvoidmain(String[]args){Integer[]array={1,2,3,4,5};List<Integer>list=......
  • php多维数组排序 array_multisort
    参考文章:https://www.cnblogs.com/ivy-zheng/p/12557645.htmlarray_multisort — 对多个数组或多维数组进行排序array_multisort() 可以用来一次对多个数组进行排序,或者根据某一维或多维对多维数组进行排序。关联(string)键名保持不变,但数字键名会被重新索引返回值成功时返......
  • F.array
    F.array()是PySpark中的一个函数,用于将多个列组合成一个数组类型的列。F通常是pyspark.sql.functions模块的简写方式,便于调用。语法  pyspark.sql.functions.array(*cols)参数  *cols:需要组合成数组的多个列。这些列可以是直接传入的列名(字符串)或使用F.col("colu......
  • array
    arrayarray<T,N>模板定义了一种相当于标准数组的容器类型。它是一个有N个T类型元素的固定序列。除了需要指定元素的类型和个数之外,它和常规数组没有太大的差别。显然,不能增加或删除元素。模板实例的元素被内部存储在标准数组中。和标准数组相比,array容器的额外幵销很小,但......
  • 错误 1 error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MTd_StaticDebug”
    前言全局说明VisualStudio2013jsoncpp0.10.7库编译LNK2038一、说明环境:Windows7旗舰版VisualStudio2013二、错误内容错误1errorLNK2038:检测到“RuntimeLibrary”的不匹配项:值“MTd_StaticDebug”不匹配值“MDd_DynamicDebug”(mfc_mqtt-client-po......
  • Java中ArrayList集合—基础详解(知识点+代码示例)
    ArrayList(集合)ArrayList(集合)ArrayList(集合)10.1ArrayList成员方法10.2集合练习10.2.1添加字符串10.2.2添加数字10.2.3添加学生对象并遍历10.2.4集合概述:集合可以直接存储引用数据类型,不能直接存储基本数据类型,如果要存储基本数据类型,需要将基本数据类型变成对......
  • day46-dynamic programming-part13-8.17
    tasksfortoday:1.647.回文子串2.516.最长回文子序列--------------------------------------------------------------------1.647.回文子串Inthispractice,itisimportanttofigureouttheessencetodecideifastringatargetone,thestring[i,j]is......
  • Sasha and Array
    维护斐波那契数列乘上一个矩阵可以快速得出斐波那契数列这个比较简单~cpp#include<bits/stdc++.h>#defineclosestd::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)usingnamespacestd;typedeflonglongll;constllMAXN=3e5+7;constllmod=1e9+......