子コンポーネントはどのようにその値を親コンポーネントに渡すことができますか?ここに私の子コンポーネントは次のとおりです。親コンポーネントに値を渡す
Javascriptを:
new Vue({
el: '#table-list',
data: {
tableList: ['Empty!'],
tableSelected: ""
},
methods: {
getTableList() {
axios
.get('/tables')
.then(tableList => {
this.tableList = tableList.data;
})
.catch(e => console.warn('Failed to fetch table list'));
},
selectTable(table) {
this.tableSelected = table;
}
},
mounted() {
this.getTableList();
}
});
HTML:
<div id="table-list">
<p v-for="table in tableList">
<i class="fa fa-table" aria-hidden="true"></i>
<span class="text-primary" v-on:click="selectTable(table)"> {{ table }} </span>
</p>
</div>
クリックで、selectTable
が呼び出されると、私はその親コンポーネントの値を表示するようにしたいですか?つまり、親コンポーネントにtableSelected
プロパティを渡す必要があります。どうすればこのことができますか?
子コンポーネントから親データを更新する可能性があります(https://stackoverflow.com/questions/40915436/vuejs-update-parent-data-from-child-component) – thanksd