0

我使用计算属性返回当前用户视图的路由参数。返回值在 devtools 中定义,如下所示,但是当我尝试mounted()通过 console.log 在我的函数中访问它时,它返回为未定义。我在想将 console.log 包装在 a 中$nextTick可以解决这个问题,但事实并非如此。我没主意了。

开发工具截图:

我的代码:

  updated() {
    this.fetchGroupMessages();
  },
  mounted() {
    let listenerID = "UNIQUE_LISTENER_ID";
    this.$nextTick(() => {
      this.getUser();
      console.log(this.reservationId);
    });
  },
computed: {
    reservationId() {
      return this.$route.params.reservationId;
    }
  },

对于更多上下文,我正在构建一个App.vue在其beforeCreated()钩子中初始化的聊天应用程序,然后在钩子中对用户进行身份验证created()。最后,Chat.vue组件呈现 if isLoggedIn == true

编辑:路线/网址

export default {
    routes: [{
        path: "/admin",
        name: 'adminDashboard',
        component: AdminDashboard
    },
    {
        path: "/",
        name: "dashboard",
        component: Dashboard
    },
    {
        name: "bookings",
        path: "/bookings",
        component: Bookings
    },
    {
        path: "/reservation/:reservationId",
        children: [
            { path: "", component: Gallery },
            { path: "media/:mediaId", component: Media }
        ],
        component: Reservation
    },
    {
        name: "shopping-cart",
        path: "/bag",
        component: ShoppingCart
    },
    {
        name: "Thanks",
        path: "/thanks",
        component: Thanks
    }],
    add: function (component) {
        this.routes.push({
            path: component.path,
            children: component.children,
            name: component.name,
            component: component
        });
    }

4

1 回答 1

0

确保您传递routerVue配置中。这就是$route反应的原因。

于 2019-11-10T08:47:09.110 回答