【问题标题】:How to pass data from child to parent in vue如何在vue中将数据从孩子传递给父母
【发布时间】:2019-04-17 10:34:24
【问题描述】:
axios.defaults.headers.common['Authorization'] = "Bearer "+localStorage.getItem('token'); 
              axios.get(baseUrl+'/country/fetch/'+id)
              .then((response) => {



                })
                .catch(function (error) {
                console.log(error);
            });

请帮助我将数据从孩子传递给父母。在这里,我得到数据作为响应。现在我想将此传递给父母我该怎么做?

【问题讨论】:

标签: laravel vue.js


【解决方案1】:

Vue 有一个简单的方法。

从父母到孩子:使用道具

从孩子到父母:使用事件

这意味着您的 childComponent 应该调用 then 部分:

this.$emit('newData', response)

你的 parentComponent 应该听它:

标记

<childComponent @newData="handleNewData"/>

组件代码

methods: {
    handleNewData(data) {
        console.log(data)
    }
}

【讨论】:

    猜你喜欢
    • 2021-10-31
    • 2021-10-16
    • 1970-01-01
    • 2022-11-21
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 1970-01-01
    • 2016-09-12
    相关资源
    最近更新 更多