vue属性绑定v-bind

属性绑定v-bind

双大括号不能在HTML attributes 中使用。想要响应式地绑定一个attribute,应该使用v-bind指令。

v-bind 指令指示Vue将元素id attribute 与组件的dyid属性保持一致。如果绑定值是null或者undefined,那么该attribute将会从渲染的元素上移除。

运行结果:

简写

因为v-bind:非常常用,可以将v-bind:简写为:。

动态绑定多个

bash 复制代码
<template>
<div v-bind="objectof">App</div>
</template>
<script>

export default{
    data(){
        return{
          objectof:{
            id:'appid',
            class:'appclass'
          }
        }
    }
}

</script>
<style scoped>
.appclass{
    color: red;
}
#appid{
    background-color: yellow;
}
</style>

运行结果:

相关推荐
传人once30 分钟前
页面中心圆圈放大效果如何写
开发语言·javascript·ecmascript
用户033307413951 小时前
TypeScript using 与 AsyncDisposableStack:在真实服务端代码中协调多资源清理
前端
web3d5201 小时前
Vue3 地图白屏排查清单:容器、弹窗与 ol-viewport 重复创建
vue.js·gis
daisychey1 小时前
用 Playwright 做多平台内容分发,我踩过的 8 个坑
前端
IT_陈寒2 小时前
为什么你应该学习JavaScript?
前端·人工智能·后端
大龄秃头程序员2 小时前
iOS冷启动监控Demo
前端
光影少年2 小时前
为什么 JavaScript 中 0.1 + 0.2 !== 0.3,如何让其相等?
前端·javascript·算法
掘金酱3 小时前
[稀土掘金 × 火山引擎] AI用量周榜冲刺赛|获奖名单公示
前端·人工智能·后端
泡泡oO3 小时前
“如果你还在用Superpowers,那我不要和你说话”
前端·后端·全栈
维克兜率天3 小时前
趋势过滤:避免被“假突破“反复打脸
前端