【问题标题】:How to pass dynamic props through <router-view>如何通过 <router-view> 传递动态道具
【发布时间】:2020-01-15 22:57:53
【问题描述】:

我在 vue 中有一个应用程序并注册了路由器,我所需要的只是将动态 props 传递给一些组件。

app.vue

<template>
  <v-app>
    <router-view :user="userVariable"></router-view>
  </v-app>
</template>

路由器.js

Vue.use(Router);
export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login,
      props: true,
    },
    {
      path: '/profile',
      name: 'profile',
      component: Profile,
      props: true,
    },
  ],
});

我在启动组件时获得了道具,但在更新值为userVariable 时无法获得更新的道具。 :(

【问题讨论】:

  • 想确认有关问题的一些信息,您无法获取组件中对象的更新值吗?如果是,则在属性“deep”为真的属性上尝试观察者。

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


【解决方案1】:

我创建了this CodeSanbox example,其中一切似乎都运行良好。

当您传递的变量是 原始非原始 值时,我已经尝试了这两种情况。

【讨论】:

    猜你喜欢
    • 2019-08-09
    • 2016-12-12
    • 2019-06-02
    • 2018-12-17
    • 2017-05-18
    • 1970-01-01
    • 2018-02-28
    • 2018-07-17
    • 2018-11-20
    相关资源
    最近更新 更多