[英]How to retrieve data from vue component in another component?
There is a vue royter 有一个老虎机
.....
const Edit = Vue.component('edit', require('./components/pages/edit.vue'));
const Product_category = Vue.component('home', require('./components/pages/product_categories.vue'));
const routes = [
........
{
path: '/product_categories',
name: 'product_categories',
component: Product_category
},
{
path: '/product_categories/edit/:id',
name: 'product_categories_edit',
components: {default: Edit, entity: Product_category},
props: {default: true, entity: true}
}
];
How can I get data in component Product_category componate Edit? 如何在组件Product_category组件编辑中获取数据?
<script>
export default {
props: ['id', 'entity'],
mounted: function () {
console.log('Admin edit page mounted.');
console.log(this.entity); // Eror
console.log(entity); // Eror
this.getData();
},
}
</script>
A direct appeal is not suitable, because each router will have its own entity. 直接上诉是不合适的,因为每个路由器都有自己的实体。
Use vuex if you prefer a global state-object. 如果您希望使用全局状态对象,请使用vuex。 It's properties can be mapped to each instance and component https://github.com/vuejs/vuex
它的属性可以映射到每个实例和组件https://github.com/vuejs/vuex
If you prefer an event based approach use an event bus https://alligator.io/vuejs/global-event-bus/ 如果您喜欢基于事件的方法,请使用事件总线https://alligator.io/vuejs/global-event-bus/
It is all well described at multiple positions in the official vuejs documentation. 官方vuejs文档中的多个位置都对此进行了很好的描述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.