<template>
<ul>
<li v-for="(item, index) in items" :key="index">
{{ item }}
</li>
</ul>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const items = ref(['苹果', '香蕉', '橙子', '葡萄']);
return {
items
};
}
};
</script>
<style scoped>
ul {
list-style-type: none;
padding: 0;
}
li {
margin: 5px 0;
}
</style>
模板部分 (<template>
):
v-for
指令遍历 items
数组,并为每个元素创建一个 <li>
列表项。:key="index"
绑定一个唯一的键值(这里使用索引作为键值,实际开发中建议使用唯一标识符)。脚本部分 (<script>
):
ref
函数定义一个响应式数组 items
。items
以便在模板中使用。样式部分 (<style scoped>
):
下一篇:vue开发小程序
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站