Vue.js,将数据传递到另一条路线上的组件 [英] Vue.js, pass data to component on another route

查看:61
本文介绍了Vue.js,将数据传递到另一条路线上的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将数据从一页传递到另一页的简单任务令Vue.js中的新手感到非常头疼这是我的路由器

Simple task to pass data from one page to another made a real headache to newbie in Vue.js Here is my router

我正在"/"页面上呈现一个表单,该表单发出了API请求,

I'm rendering a form on "/" page, which make an API request,

,我只想将数据与另一个组件传递到另一个路由页面

and I just want to pass data to another route page with another component

在Vue中难做吗?今天让我感到非常头疼.从API获取数据,然后保存并保存发送到另一个组件.我该怎么办?

Is it so hard to do in Vue? It made a real headache for me today. Get data from API, save & send to another component. How can I do it?

推荐答案

正如安东尼所说,由于您已经在 router/index.js 中启用了props,因此可以在中传递参数router.push 像这样:

As Antony said, since you've already enabled props in router/index.js, you can pass parameters in router.push like this:

router.push({
    name: 'events',
    params: {
        items: data
    }
});

然后您将能够在 EventsDisplay.vue

export default {
    name: 'eventsDisplay',
    props: ['items'],
};

这篇关于Vue.js,将数据传递到另一条路线上的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆