A.vue
axios.post('/api/user', {
username: 'Fred'
}).then(function (response) {
this.user = response.data;
}).catch(function (error) {
console.log(error);
});
B.vue
axios.post('/api/user', {
username: 'Fred'
}).then(function (response) {
this.user = response.data;
}).catch(function (error) {
console.log(error);
});
Index.vue
<template>
<A />
<B />
</template>
这样写,访问首页会请求两次
###在Index.vue中获取用户的数据呀,然后把数据传递给子组件就可以了
###如果小项目可以用eventbus啊,有必要也可以上vuex
###可以用props
传入,项目如果很多地方都有用到并且要同步更新的话,还是建议你上 vuex