【问题标题】:Vue2 js pass some values from input of one route to another route or share data property from one route to another routeVue2 js将一些值从一条路由的输入传递到另一条路由或从一条路由共享数据属性到另一条路由
【发布时间】:2018-01-06 04:19:24
【问题描述】:

在 vue2 js 中做一个酒店房间预订应用程序。有两个屏幕 1) 一个获取搜索输入值 2) 显示搜索结果页面。请看下面的屏幕截图

我的route.js如下

import FrontEndHome from './components/fontend/Home.vue';
import FrontEndCheck from './components/fontend/Check.vue';

export const routes = [
    { path: '/', component: FrontEndHome },
    { path: '/check', component: FrontEndCheck }
];

我想要的是必须从第一张图像中获取日期,并且必须在第二张图像中显示这些日期。

【问题讨论】:

  • { path: '/check/:from/:to', component: FrontEndCheck, props: true }

标签: vue.js vuejs2 vue-component vue-router


【解决方案1】:

您想通过路由传递数据。你可以在 vue 的文档https://router.vuejs.org/en/essentials/passing-props.html中看到如何实现这一点

【讨论】:

    【解决方案2】:

    您可以在 app.vue 中执行以下操作:

    <template>
      <router-view :items="items"></router-view>
    </template>
    <script>
    export default {
      name: 'app',
      data() {
        return {
          items: 6
        }
      },
    }
    </script>
    

    在 Check.vue 组件中:

    <template>
      <div>{{items}}</div>
    </div>
    </template>
    <script>
    export default {
      name: 'FrontEndCheck',
      props: ['items'],
    }
    </script>
    

    换句话说,您可以将组件道具的逻辑应用于router-view(因为它是一个组件)。它适用于我的应用程序。

    【讨论】:

      猜你喜欢
      • 2019-09-22
      • 2018-04-02
      • 2020-11-26
      • 1970-01-01
      • 2017-12-18
      • 2021-05-27
      • 1970-01-01
      • 2012-01-21
      • 1970-01-01
      相关资源
      最近更新 更多