Vue 模板使用声明式语法描述界面。常用指令包括 v-if、v-for、v-bind 和 v-on。
本节要点
- 双大括号用于文本插值。
- v-bind 绑定属性,可以简写为冒号。
- v-on 绑定事件,可以简写为 @。
代码示例
<template>
<h1>{{ title }}</h1>
<button :disabled="loading" @click="load">刷新</button>
<ul>
<li v-for="item in list" :key="item.id">{{ item.name }}</li>
</ul>
</template>
<script setup>
import { ref } from "vue";
const title = ref("Vue 教程");
const loading = ref(false);
const list = ref([{ id: 1, name: "HTML" }]);
</script>