当前位置: 首页 > news >正文

vue 的属性绑定

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

<template>
<div v-bind:class="boxClass" v-bind:id="boxId">
</div>
</template><script>
export default{data(){return{boxClass:"box1",boxId: "boxid1"}}
}
</script>

 

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

由于v-bind比较常用 所以可以简写,将v-bind省略只留下冒号。

<div :class="boxClass" :id="boxId"></div>

布尔型 

布尔型 attribute 依据 true /false 值来决定 attribute 是否应该存在于该元素上,disabled 就是最常见的例子之一。

<template>
<div :class="boxClass" :id="boxId"><button :disabled="flag"></button>
</div>
</template><script>
export default{data(){return{boxClass:"box1",boxId: "boxid1",flag:true,}}
}
</script>

动态绑定多个值 

如果需要绑定多个值可以使用js的对象来实现

<template>
<div v-bind="object"></div>
</template><script>
export default{data(){return{object:{boxClass:"box1",boxId:"boxid1"}}}
}
</script>

http://www.lryc.cn/news/456913.html

相关文章:

  • 【附源码】Python :打家劫舍
  • YOLO11改进 | 注意力机制| 对小目标友好的BiFormer【CVPR2023】
  • 高级Python开发工程师的面试备考指南
  • 【Java】JAVA知识总结浅析
  • 23-云原生监控系统
  • 信息安全工程师(40)防火墙技术应用
  • Liquid AI与液态神经网络:超越Transformer的大模型架构探索
  • Spring Boot 进阶-详解Spring Boot中使用Swagger3.0
  • Linux平台Kafka高可用集群部署全攻略
  • Android中有哪些布局方式?
  • Apache Ranger 70道面试题及参考答案
  • 2024年9月30日--10月6日(ue5肉鸽结束,20小时,共2851小时)
  • 什么是静态加载-前端
  • (01)python-opencv基础知识入门(图片的读取与视频打开)
  • quic-go实现屏幕广播程序
  • C#操作SqlServer数据库语句
  • Linux之实战命令33:mount应用实例(六十七)
  • 论文精读:基于概率教师学习的跨域自适应目标检测(ICML2022)
  • thinkphp 学习记录
  • Leetcode 24 Swap Nodes in Pairs
  • 选择 PDF 编辑器时要考虑什么?如何选择适用于 Windows 10 的 PDF 编辑器
  • 33-Golang开发入门精讲
  • 研发中台拆分之路:深度剖析、心得总结与经验分享
  • SWIFT Payment
  • 数据结构之红黑树实现(全)
  • 冷热数据分离
  • 朝花夕拾:多模态图文预训练的前世今生
  • 亳州自闭症寄宿制学校,关注孩子的学习和生活
  • Root me CTF all the day靶场ssrf+redis漏洞
  • C#中Json序列化的进阶用法