Vue3.2 官方中文档 阅读心得

371 阅读1分钟

Attribute 绑定#

双大括号不能在 HTML attributes 中使用。相应的,应该使用 v-bind 指令

<div v-bind:id="dynamicId"></div>

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

📒dynamicID 理解为变量名吗?📒

<script setup>
  const dynamicId = "age";
</script>

<template>
  <div v-bind:id="dynamicId">这里的div标签 id 为 age </div>
</template>

编译结果

<div id="age">这里的div标签 id 为 age </div>

如果可以的话,应该会在后面不定时间的慢慢慢慢的写一部分。 --2022年3月1日