vue中属性及样式绑定

vue中属性及样式绑定

直接上代码 那个不会点哪里

<template>
  <div class="home">
      第一种直接写class
      <!--<div class="circle">//直接写class-->
      第二种使用data中属性动态绑定的样式
      <!--<div :class="className">//使用data中属性动态绑定样式-->
      第三种绑定多个class的方法
      <!--<div :class='{"circle":true,"text":show}'>//绑定多个class使用key-value的形式,其中true可以用data中定义的属性代替-->
      第四种混合写法
      <!--<div class="circle" :class='{"text":show}'>//混着写两种方式都可以一起使用-->
      第五种以数组的形式
      <!--<div :class='[dataCircle,dataText]'>//数组形式 数组里面的数据是data中定义好的-->
      第六种三元表达式
      <!--<div :class='[show?dataCircle:dataText]'>//数组形式就比较强大可以直接在这里面写三元 和对象等 此时show为true则使用dataCircle-->
      第七种数组和对象
      <!--<div :class='[{circle:show},"text"]'>//数组结合对象的形式-->
      绑定内联样式
      <!--<div :style='{"width": "100px","height": "100px","background-color": "pink"}'>//对象直接和css结合-->
      <div :style='{backgroundColor,color}'>//直接使用对象值为data中定义好的</div>
  </div>
</template>

<style lang="scss" scoped>
    .circle{
        width: 100px;
        height: 100px;
        background-color: pink;
        border-radius: 50%;
    }
    .text {
        text-align: center;
        line-height: 100px;
        color: white;
    }
</style>

<script>
// @ is an alias to /src
import { defineComponent,ref } from 'vue'
export default defineComponent({
    name: 'Home',
    data(){
        return {
            backgroundColor:"pink",
            color:"red",
            size:{
                width: "100px",
                height:"100px",
                borderRadius:"50%",
            },
            className:"circle",
            password:123,
            show:true,
            dataCircle:"circle",
            dataText:"text",
        };
    },
    })

如有错误欢迎指正

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值