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>

运行结果:

相关推荐
蜡台4 分钟前
IDEA LiveTemplates Vue ElementUI
前端·vue.js·elementui·idea·livetemplates
E-cology7 分钟前
【泛微低代码开发平台e-builder】使用HTML组件实现页面中部分区域自定义开发
前端·低代码·泛微·e-builder
苏瞳儿10 分钟前
前端/后端-配置跨域
前端·javascript·node.js·vue
TheRouter12 分钟前
AI Agent 开发中的模型调度策略:何时用便宜模型,何时用强模型
前端·人工智能·react.js
神の愛15 分钟前
Vite的proxy和Nginx的location 请求转发区别
vue.js
竹林81815 分钟前
从轮询到订阅:我在 React 项目中实现实时监听 ERC-20 转账事件的完整踩坑记录
前端·javascript
Mapmost16 分钟前
别乱调了!Mapmost 渲染第一步:选对HDRI,让你直接赢在起跑线
前端
技术爬爬虾17 分钟前
OpenCode详细攻略,开源版Claude Code,免费模型与神级插件
前端·后端