Can the Vue sub-component api get the data and load it?

the project structure is the original demo, built by vue-cli. The purpose of the demo, is to test the component development of vue + element-ui and to use it in the background development.

expectation:

the parent component loads each child component (independent module) and shows that each child component invokes api, to get the data and renders the View, and then renders it in the parent component.

question:

The

question is reduced to why I call initApiData () in created to update the data, and the table data remains the same?

<template>
    <el-container>
        <el-main>
            <el-table :data="tableData">
                <el-table-column prop="date" label="" width="140">
                </el-table-column>
                <el-table-column prop="name" label="" width="120">
                </el-table-column>
                <el-table-column prop="address" label="">
                </el-table-column>
            </el-table>
        </el-main>
    </el-container>
</template>

<script>
//import Users from "@/components/user/Users"

export default {
    name: "Home",
  data () {
    const item = {
      date: "2016-05-02",
      name: "",
      address: " 1518 "
    }
    return {
      tableData: Array(20).fill(item),
      tableData2: Array(1).fill(item)
    }
  },
    methods: {
        initApiData: function () {
            let that = this
            console.log("change data...")
            that.tableDate = that.tableData2
            console.log(that.tableData2)
        }
    },
    created: function () {
        console.log("created...")
        this.initApiData()
    }
}
</script>
Jun.22,2021

should not. The properties of data objects are all responsive. As long as they are re-assigned, they will trigger setter , which in turn will trigger dependency updates in view , and find out why.


App.vue template does not lazily load keep-alive, if it comes in again, it will not execute this function. If it is not lazily loaded, make sure that the function is executed (you can print a console.log ('initApiData') in the initApiData function) and print tableData data after execution, then use $set to force rendering.


Big Brother made a mistake here: 'that.tableDate = that.tableData2 that.tableDate' tableDate = > tableData

Menu