Parent and child components pass values?

parent father.vue:
< template >

<div>
    <A></A>
    <B></B>
</div>

< / template >
where component An is the table component, and the data in the table is passed in by the father component.
B is a component that adds Form form data. If you want to add data to the table of component A through component B, how do you write vue code?

Aug.17,2021

<template>
  <div>
    <A :table-data="tableData"></A>
    <B @on-add="onAddTableData"></B>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        tableData: [],
      };
    },
    methods: {
      onAddTableData(data) {
        this.tableData.push(data);
      },
    },
  };
</script>

is something like this: component B adds the form and notifies the parent component to add data through $emit ('on-add', newData) , and component A updates

accordingly.

to achieve bidirectional data binding between parent and child components, you can use sync

Menu