简体   繁体   English

在Vue js路由之间传递大量数据

[英]Passing Huge data between Vue js routes

I have an application which searches for flights using Vue.js and Vue Router. 我有一个使用Vue.js和Vue Router搜索航班的应用程序。

I have two components, first one is search, which is on the base route '/'. 我有两个组成部分,第一个是搜索,它位于基本路线“ /”上。 When user clicks on search, it will send a request to server and gets a huge list of flights. 当用户单击搜索时,它将向服务器发送请求并获得大量航班。

Then I need to call the result component on '/results' route and show the results using v-for. 然后,我需要在“ /结果”路线上调用结果组件,并使用v-for显示结果。

I have two questions, first, how can I manually redirect to '/results' after I get the results. 我有两个问题,首先,获得结果后,如何手动重定向到“ /结果”。

Second and more important, what is the proper way of passing the results data to results component to use? 其次,更重要的是,将结果数据传递给结果组件以使用的正确方法是什么?

Inside your results components, you can put transition hooks in the route object. 在结果组件内部,可以将转换钩子放置在route对象中。 Read here: http://vuejs.github.io/vue-router/en/pipeline/hooks.html 在这里阅读: http : //vuejs.github.io/vue-router/en/pipeline/hooks.html

The activate hook runs when a component is activated, and the component wont appear until the activate hook has run. activate挂钩会在激活组件时运行,并且直到激活挂钩运行后组件才会出现。 Here's the example on that page, which would be similar to yours: 这是该页面上的示例,与您的示例类似:

route:{
  activate: function (transition) {
    return messageService
      .fetch(transition.to.params.messageId)
      .then((message) => {
        // set the data once it arrives.
        // the component will not display until this
        // is done.
        this.message = message
    })
  }
}

So basically when they click search you send them to /results and this hook will handle loading the data in between. 因此,基本上,当他们单击搜索时,您会将它们发送到/results ,此钩子将处理之间的数据加载。

Here's an advanced example of a mail app using vue-router that shows off a lot of the transition hooks in action: https://github.com/vuejs/vue-router/tree/dev/example/advanced 这是一个使用vue-router的邮件应用程序的高级示例,该示例演示了许多正在使用的转换挂钩: https : //github.com/vuejs/vue-router/tree/dev/example/advanced

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM