【vue-3】动态属性绑定v-bind

1、文本动态绑定:

<input type="text" v-bind:value="web.url">

简写:

<input type="text" :value="web.url">

 2、文字样式动态绑定

<b :class="{textColor:web.fontStatus}">vue学习</b>

完整示例代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="vue.global.js"></script> -->
    <style>
        .textColor{
            color:blue
        }
    </style>
</head>
<body>
    <div id="app">
    <h1>value="www.vue.com"</h1>   
    <input type="text" value="vue.com"> 

    <h1>v-bind:value="web.url"</h1>   
    <input type="text" v-bind:value="web.url"> 

    <h1>:value="web.url"</h1>   
    <input type="text" :value="web.url"> 

    <h1>src="test.jpg"</h1>   
    <img src="test.jpg">
    
    <h1>:src="web.img"</h1>   
    <img :src="web.img">

    <h1>class="textColor"</h1>
    <b class="textColor">vue学习</b>

    <h1>:class="{textColor:web.fontStatus}"</h1>
    <b :class="{textColor:web.fontStatus}">vue学习</b>
    
    </div>
    <script type="module">
        import {createApp, reactive} from './vue.esm-browser.js'
        // const {createApp, reactive} = Vue
        createApp({
            // setup选项,用于设置响应式数据和方法等
            setup(){ 
                const web = reactive({
                    url:"www.vue.com",
                    img:"test.jpg",
                    fontStatus:true
                })
                
                return{
                    web     
                }
            }
        }).mount("#app")
        // mount为挂载
    </script>
</body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: v-bind动态属性绑定Vue.js中的一个指令,用于将数据动态绑定到HTML元素的属性上。在v-bind指令中,可以使用表达式来动态绑定属性的值。对于class属性动态绑定,可以使用数组语法来绑定多个类名,例如:`<div :class="\['bdtop', 'bdbottom'\]"></div>`。这样就可以将`bdtop`和`bdbottom`这两个类名动态绑定到该元素的class属性上。\[2\]而对于style属性动态绑定,可以使用对象语法来绑定多个样式,例如:`<div :style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>`。这样就可以将`activeColor`和`fontSize`这两个变量的值动态绑定到该元素的style属性上。\[1\]如果你想了解更多关于v-bind与class和style绑定相关的内容,可以参考Vue.js的官方文档中的Class与Style绑定部分。\[3\] #### 引用[.reference_title] - *1* *3* [v-bind动态绑定](https://blog.csdn.net/qq_53841687/article/details/126048116)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [v-bind动态属性绑定](https://blog.csdn.net/weixin_68546350/article/details/124377050)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值