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>

运行结果:

相关推荐
kyriewen6 小时前
我读了一遍 Babel 编译后的 async/await,终于搞懂了它的原理(附 20 行手写实现)
前端·javascript·面试
IT_陈寒6 小时前
Vite项目build后路由404了?你可能漏了这个小配置
前端·人工智能·后端
lichenyang4537 小时前
AI 聊天从纯文本到结构化卡片:SSE done 帧携带 card + 历史记录卡片恢复实战
前端
梦曦i7 小时前
@meng-xi/vite-plugin v0.1.5:告别手动 import,精简工具层
前端
梦曦i7 小时前
Vite 0.1.6重磅更新:智能导入+路由安全
前端
gxf5203088069888 小时前
Flutter 裁剪图片
前端·app
半岛@少年8 小时前
都是JS,CJS和ESM有什么区别?
javascript·esm·前端模块化·cjs
想吃火锅10058 小时前
【leetcode】165.比较版本号js
javascript·算法·leetcode
ITMan彪叔8 小时前
赋能UE运行态编辑平台: 网络图片下载的插件改造与复盘
前端
RANxy8 小时前
🚀 Umi Max 项目从0到1:企业级 React 脚手架实战
前端·前端框架