vue父向子組件傳遞this,子向父組件傳遞方法


在vue中,父子組件傳參數

在子組件中,獲取 父組件的參數,傳遞方法

父組件中的子標簽
<son :parent="this" @comfirmParam="getFilterData" >子組件</son>
    data() {
        return {
            name:"黑波利"
        };
    },
    methods: {
        getFilterData(params) {
            console.log(params);
        },
    },
子組件中的代碼
<button @click="click"><button>

<script>
export default {
    props: ["parent"],
    data() {
        return {
            params: { name: "小熊" },
        };
    },
    methods: {
        click() {
            this.$emit("comfirmParam", this.params);
            console.log(this.parent.name)
        },
    },
};
</script>

 


免責聲明!

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



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