我正在使用 Vuetify 來呈現表格?,F在我將表格分為兩個組件:Table組件和Row組件。如果我不把它分解成兩個獨立的組件,我有一個onclick我可以簡單地在這支筆this.selected = !this.selected!中調用的一個。但是當有 2 個不同的組件時,我怎樣才能發出相同的功能呢?tr看看這個完整的沙箱。這是我的表格組件:-<template> <div class="hello"> <v-container> <v-layout> <v-data-table v-model="selected" :headers="getHeaders" :items="getTableItems" item-key="name" class="elevation-1" > <template v-slot:headers="props"> <tr> <th> <v-checkbox :input-value="props.all" :indeterminate="props.indeterminate" primary hide-details @click.stop="toggleAll" ></v-checkbox> </th> <th v-for="header in props.headers" :key="header.text"> <v-icon small>arrow_upward</v-icon> {{ header.text }} </th> </tr> </template> <template v-slot:items="props"> <Row :active="props.active" :selected="props.selected" :name="props.item.name" :calories="props.item.calories" :fat="props.item.fat" /> </template> </v-data-table> </v-layout> </v-container> </div></template><script>import { mapGetters } from "vuex";import Row from "./Row";export default { name: "Table", components: { Row }, data() { return { selected: [] }; }, computed: { ...mapGetters({ getHeaders: "getHeaders", getTableItems: "getTableItems" }) }, methods: { toggleAll() { if (this.selected.length) this.selected = []; else this.selected = this.getTableItems.slice(); } }};</script>這是我的行組件:-<template> <tr :active="active"> <td> <v-checkbox :input-value="selected" primary hide-details></v-checkbox> </td> <td>{{name}}</td> <td>{{calories}}</td> <td>{{fat}}</td> </tr></template>任何幫助將不勝感激。謝謝你。
如何在 VueJS 中發出事件?
慕碼人2483693
2022-07-21 11:03:51