vue3--学习技术胖笔记
作者:互联网
<template>
<div>
<a href="https://vitejs.dev" target="_blank"></a>
<H2>欢迎光临红浪漫洗浴中心</H2>
<div>请选择一位美女</div>
<button
v-for="(item,index) in girls"
v-bind:key="index"
@click="selectGirlFun(index)"
>
{{index}}:{{item}}
</button>
<div>你选择了【{{selectGirl}}】为你服务</div>
</div>
</template>
<script lang="ts">
import {defineComponent,ref} from "vue";
export default defineComponent({
name:"APP",
setup(){
const girls =ref(["大脚","刘颖","小红"]);
const selectGirl =ref("");
const selectGirlFun = (index:number)=>{
selectGirl.value=girls.value[index];
}
return{girls,
selectGirlFun,
selectGirl
}}});
</script>
1、方法和值都写到了setup里面就可以了
标签:index,const,--,ref,girls,笔记,selectGirlFun,vue3,selectGirl 来源: https://www.cnblogs.com/kaibindirver/p/16671367.html