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>

运行结果:

相关推荐
次次皮1 天前
Linux 下通过 XShell 手动更新 Tomcat 应用并重启
前端·tomcat·jar
猫猫不是喵喵.1 天前
Vue 3 项目创建指南:基于 Vue CLI 与 Vite 的两种方式
前端·javascript·vue.js
swipe1 天前
14|(前端转全栈)商品详情高频访问怎么扛?Redis Cache Aside 实战
前端·后端·面试
swipe1 天前
15|(前端转全栈)从一个副标题字段看懂后端完整交付链路
前端·后端·面试
卸任1 天前
LocalTab:一个本地化、简洁且可定制的浏览器新标签页
前端·浏览器
间彧1 天前
从火焰图到代码:如何揪出“用久必卡”的前端性能瓶颈
前端
张元清1 天前
React useThrottle Hook:节流值与回调(2026)
javascript·react.js
米码收割机1 天前
【前端】html_css 沐光公益阅读馆(源码+文档)【独一无二】
前端·css·html
Apifox1 天前
Apifox 7 月更新|审计日志、密钥扫描防护、Postman/OpenAPI / Swagger 导入体验优化
前端·后端·测试
名字还没想好☜1 天前
Next.js App Router 约定式文件实战:loading、error、not-found 怎么兜住加载态与异常
开发语言·前端·javascript·react·next.js