首页 > 其他分享 >10绑定class,绑定style文件

10绑定class,绑定style文件

时间:2022-12-28 21:45:14浏览次数:32  
标签:10 style mood solid 绑定 background border

绑定样式总结

  1. class样式
    写法:
    :class="xxx" xxx可以是字符串、对象、数组。
    字符串写法适用于:类名不确定,要动态获取。
    对象写法适用于:要绑定多个样式,个数不确定,名字也不确定。
    数组写法适用于:要绑定多个样式,个数确定,名字也确定,但不确定用不用。
  2. style样式
    :style="{fontSize: xxx}" 其中xxx是动态值。
    :style="[a,b]"其中a,b是样式对象。

一、绑定class文件


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>绑定样式</title>
    <style>
        .basic{
            /* border-style:groove; */
            /* border: 2px solid black; */
            width: 400px;
            height: 400px;
        }
        .happy{
            border: 4px solid red;
            /* background-color: rgba(255, 255, 0, 0.644); */
            background:linear-gradient(30deg,red,pink,orange,yellow);
        }
        .sad{
            border: 4px solid blue;
            border-radius: 5px;
            /* background-color: orange; */
            /* background-color: rgba(255, 0, 89, 0.644); */
            background:linear-gradient(30deg,blue,pink,orange,yellow);
        }
        .normal{
            border:4px solid grey;
            border-radius: 5px;
            background: linear-gradient(30deg,grey,grey,pink,orange);
        }
    </style>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <!--
        准备好一个容器
    -->
    <div id="root">
        <!-- <div class="basic" :class="mood" @click="change(); test()" >test</div> -->
        <div class="basic" :class="mood" @click="change" >心情随机测试</div>
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
   
    const vm = new Vue({
        el: '#root',
        data: {
            trigger: false,
            mood: 'sad'
        },
        methods: {
            change(){
                const arr = ['happy','sad','normal']
                const i = Math.floor(Math.random()*3)  //最多到2.***,不会到3
                this.mood = arr[i]
                console.log(this.mood)
            }
            // change() {
            //     if(this.mood === 'sad') this.mood = 'happy'
            //     else this.mood = 'sad'
            // },
            // test() {
            //     console.log(this.mood)
            // }
        },
    })
</script>
</html>


代码格式效果如下:

二、绑定style文件


<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>绑定样式-style</title>
    <style>
        .basic{
            /* border-style:groove; */
            /* border: 2px solid black; */
            border: 4px solid black;
            width: 400px;
            height: 400px;
        }
        .happy{
            border: 4px solid red;
            /* background-color: rgba(255, 255, 0, 0.644); */
            background:linear-gradient(30deg,red,pink,orange,yellow);
        }
        .sad{
            border: 4px solid blue;
            border-radius: 5px;
            /* background-color: orange; */
            /* background-color: rgba(255, 0, 89, 0.644); */
            background:linear-gradient(30deg,blue,pink,orange,yellow);
        }
        .normal{
            border:4px solid grey;
            border-radius: 5px;
            background: linear-gradient(30deg,grey,grey,pink,orange);
        }
    </style>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <!--
        准备好一个容器
    -->
    <div id="root">
        <div class="basic" :class="mood" @click="change" >心情随机测试</div><br/><br/>
       
       
        <div class="basic" :style="styleObj">{{name}}</div>
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
   
    const vm = new Vue({
        el: '#root',
        data: {
            name:'基督山',
            trigger: false,
            mood: 'sad',
            styleObj:{    //style格式的对象写法,即定义为:键值对形式的对象。
                fontSize:'40px',
                color:'red'
            }
        },
        methods: {
            change(){
                const arr = ['happy','sad','normal']
                const i = Math.floor(Math.random()*3)  //最多到2.***,不会到3
                this.mood = arr[i]
                console.log(this.mood)
            }
        }
       
    })
</script>
</html>

标签:10,style,mood,solid,绑定,background,border
From: https://www.cnblogs.com/quliangshyang/p/17011336.html

相关文章

  • gym104076H
    hehezhou的鬼才神仙题解根本看不懂好吧。首先判掉\(n=1\)。然后考虑最后一步,发现只用考虑怎样的左右端点可能见面。左右和右左构成双射,算出总量减去自己配自己再除\(......
  • Win 10 x64 Visual Studio 2019 编译 Detours 4.0.1
    Win10x64VisualStudio2019编译Detours4.0.1 十一年前,研究项目里用到的Detours已经更新到版本4.0.1,支持64位HOOK,从Github上下载下来编译看一下。GitHub下载......
  • Redis Desktop Manager for Mac(Redis桌面管理工具) v2021.10.236中文版
    RedisDesktopManagerforMac是Mac平台上一款非常实用的Redis可视化工具。RDM支持SSL/TLS加密,SSH隧道,基于SSH隧道的TLS,为您提供了一个易于使用的GUI,可以访问您的Redis......
  • vue中 WebSocket connection to 'ws://192.168.10.103:8080/ws' failed 问题的解决
    首先吧 vue中WebSocketconnectionto'ws://192.168.10.103:8080/ws'failed这个报错它不会影响你代码的运行,但是报错一定程度上影响页面的美观度。   下面我们......
  • P1024 [NOI2001] 食物链【种类并查集】
    题意P1024简化题意:给定\(n\)和\(k(n\leqslant5\times10^4,k\leqslant10^5)\),表示有\(n\)个动物,\(k\)个描述,其中:\(n\)个动物分别属于\(A,B,C\)中的一种,定义......
  • 判断101-200之间有多少个素数,并输出所有素数
      问题分析:题目中的关键词是素数,什么是素数?素数就是只能被1和自身整除的数,例如11就是素数,但12就不是,因为12可以被1,2,3,4,6和12整除,故12就不是素数;但11就只能被1和11整除,所以......
  • 10-NoSQL_Redis
    目录​​一,redis介绍​​​​1,什么是NoSQL​​​​2,为什么要使用NoSQL​​​​3,常见的NoSQL产品​​​​4,各产品的介绍​​​​5,什么是Redis​​​​5.1Redis介绍​​​​5......
  • P1060 开心的金明
    P1060开心的金明题意:01背包问题思路:01背包模板实现:#include<stdio.h>#include<algorithm>usingnamespacestd;intdp[30005]={0};intval[30];intlev[3......
  • 10.过滤
    182.查找重复的电子邮箱i.1#WriteyourMySQLquerystatementbelow2SELECT3Email4FROM5Person6GROUPBYEmail7HAVINGCOUNT(Email)>1ii.哈哈,......
  • layui table 动态生成复杂表头 及 数据绑定问题
    table复杂表头 下面将是我们要实现的效果下面是后台返回的数据    复杂表头重要的属性:rowspancolspan需要注意的是循环生成表头时,循环时不会执行templet里......