holdtom
这是 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}; },};