父组件需要子组件返回的值作为请求参数,实现该功能,思路就是:子组件请求完成的时候 $emit, 父组件触发事件请求数据。如:
//子组件
export default{
mounted: function() {
this.$axios({
method: 'get',
url: Constants.HOME_URL + '/dealer/'
})
.then((response) => {
if(response.status === 200) {
console.log(response.data);
this.$emit('dealerIdFn',response.data.id); //该id为父组件需要的参数
}
})
}
}
//父组件
<template>
<child-node @dealerIdFn="backIdFn"></child-node>
</template>
export default{
methods:{
backIdFn:function(id){ //子组件返回的id
console.log(id);
this.getActivity(id);
},
getActivity: function(id){ //通过活动id活动信息请求
this.$axios({
method: 'get',
url: Constants.HOME_URL + '/activity/',
params:{dealerId:id}
})
.then((response) => {
if (response.status === 200) {
console.log(response);
}
});
}
}
}