v-bind 将一个 HTML attribute(或 component prop)动态绑定到 JavaScript 表达式,当数据改变时该 attribute 会响应式更新。它的简写是 :。
vue
<script setup>
import { ref } from "vue";
const imageUrl = ref("/photo.jpg");
const isDisabled = ref(true);
const id = ref("main");
</script>
<template>
<img v-bind:src="imageUrl" /> <!-- full syntax -->
<img :src="imageUrl" /> <!-- shorthand (idiomatic) -->
<button :disabled="isDisabled">Save</button>
<div :id="id" :data-index="5">...</div>
</template>
和 之间的区别至关重要:没有 时,它是一个字符串字面量;有 时,Vue 会求值该表达式。
