Prop delay problem when Vue parent component invokes child component method

when the vue parent component invokes the child component method, when the data passed by the parent component is used in the method, the data is modified before the method is called, and the data is still the original data when the child component method is called, and it will become the last modified data on the next call.

parent component

// 
<template>
    <div>
        <form action="/">
            <van-search placeholder="" v-model="keywords" @search="seachPage()" style="background: default;"/>
        </form>
        <div class="hot-search-items">
            <span>:</span>
            <span class="hot-item" v-for="item in hotItems" @click="searchItem(item)">{{ item }}</span>
        </div>
        <pageList :query="{ keywords: keywords }" :api="api" ref="pageList"></pageList>
    </div>
</template>
export default class Search extends Vue {
    keywords: string = "";
    pullLoading: boolean = false;
    list: object[] = [];
    hotItems: string[] = ["Javascript", "Vue.js", "get it", ""];
    api: string = "/api/page/searchpage";
    seachPage () {
       (this.$refs["pageList"] as any).onRefresh({ keywords: this.keywords }); 
    }
    searchItem (name: string) {
        this.keywords = name;
        this.seachPage();
    }
}
</script>

subcomponents

// 
...
onRefresh (query_obj: object) {
    console.log(this.query);
}

interface

clipboard.png

Click Javascript, and then click Vue.js to print out Javascript, and then click get it to print out Vue.js

adding a delay function to the searchPage of the parent component can solve this problem. I don"t know if there"s a better solution.

Oct.09,2021

try


it takes some time to pass


with the pre-call assignment. You'd better pass the listening value in the component, and then do what you want to do

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54661-452bc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54661-452bc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?