2 回答
TA贡献1805条经验 获得超10个赞
这是 Vuejs3 的示例,但您应该了解更多信息:
<template>
<ul>
<li v-for="user in users"
:key="user.id"
@click="showDetail(user)"
>
{{ user.id }} - {{ user.name }}
</li>
</ul>
<div v-if="clickedUser">
<h6>Detail</h6>
<span>{{ clickedUser.id }}</span>
<span>{{ clickedUser.name }}</span>
</div>
<script>
import {ref} from "vue";
export default {
setup() {
const users = [
{id: 1, name: "A"},
{id: 2, name: "B"},
{id: 3, name: "C"},
{id: 4, name: "D"},
];
let clickedUser = ref(null);
const showDetail = (user) => {
clickedUser.value = user;
};
return {users, clickedUser, showDetail};
},
};
TA贡献2012条经验 获得超12个赞
使用 vue Native 你可以简单地这样做
<view v-for="user in users" :key="user.id">
<button :on-press="()=> getDetail(user.number)" />
</view>
然后在你的脚本中
<scripts>
...
methods: {
getDetail(id){
this.number = id // assuming you already have this.number set in your data object
console.log(id)
}
}
<scripts />
添加回答
举报