简体   繁体   English

如何从另一个组件中的vue组件检索数据?

[英]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.

相关问题 Vue JS 3:如何将数据从一个组件传递到另一个组件? - Vue JS 3: How to pass data from one component to another other? 如何在Vue JavaScript中将数据从一个组件恢复到另一个组件 - How to recover data from one component to another in vue JavaScript 来自一个Vue组件的数据会影响另一个组件 - Data from one Vue component affecting another 从一个组件检索数据到另一个组件 - Retrieve the data from one component to another 将数据从组件传递到另一个组件vue.js - passing data from component to another component vue.js 如何将数据从一个组件传递到另一个组件并将该数据存储到 vue.js 中的数组中? - How to pass data from one component to another component and store that data into an array in vue.js? 如何通过Vue将数据从表组件传递到另一个表组件,并使用编辑按钮传递表中的每一行 - how pass data from a table component in vue to another table component passing each row in the table with an edit button 如何在 Vue Js 中将数据值从一个组件更改为另一个组件? - How can I change data value from one component to another component in Vue Js? 如何将数据(书籍数组长度)从一个组件传递到 vue.js 中的另一个组件? - How to pass data(books array length) from one component to another component in vue.js? Vue2如何从另一个单文件组件更改主要数据组件? - Vue2 how to change the main data component from another single file component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM