vue 子組件修改父組件傳來的props值,報錯


vue不推薦直接在子組件中修改父組件傳來的props的值,會報錯

[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "result" (found in component )

 

 <input v-model="currentSearch" type="text" class="input-search" @keydown.enter="doSearch">

 

export default {
    name:"round-search-bar",
    props:['search'],    //父組件傳來的值
    data(){
        return {
            currentSearch: this.search    //通過data, 定義新變量currentSearch, 這樣currentSearch的值變更時,不會影響父組件傳來的search的值
        }
    },
    methods: {
        doSearch(){
            Util.searchAPI(this.$router,this.currentSearch)
        }
    },
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM