【发布时间】:2021-06-19 18:26:03
【问题描述】:
我有一个模态组件(名为 modal_form.vue 的子组件),我在另一个名为 index.vue 的组件中调用它
我想将一个数据变量从modal_form.vue 发送到index.vue。
谁能给我一个例子?
PS:modal_form包含一个axios请求,所以我想将响应发送到index.vue
-- 模态--
methods: {
post() {
getAPI.post('api/contact/', this.form)
.then(response => (this.data = response.data))
.then(() => (this.$emit('dataLoaded', this.data)))
.catch(error => console.log(error.response))
}
}
-- 索引--
<addContactModal v-if="openContactModal" :dataLoaded="refreshContactList"></addContactModal>
data: function(){
return {
openContactModal: true,
contacts: []
}
},
methods: {
refreshContactList(data){
this.contacts = JSON.parse( JSON.stringify( data ) )
},
}
【问题讨论】:
-
@Vpa 无论如何都可以在没有事件侦听器的情况下执行此操作,因为我想在获得我的 axios 响应后将数据变量从模式发送到 index.vue
-
你可以使用Vuex
-
@MohammadMomeni 你能举个例子吗
标签: vue.js