【问题标题】:Vue.js getting params from router-link bindVue.js 从路由器链接绑定中获取参数
【发布时间】:2018-11-28 05:57:00
【问题描述】:

我怎样才能获得不通过 url 而是通过像 params 这样的帖子提供的参数?

<router-link v-bind:to="{ 
    path: '/city/'+city.topicID, 
    params: { countryCode: countryCode, city: city } }">

    Chat
</router-link>

this.$route.params 似乎不起作用,将显示 topicID。

【问题讨论】:

    标签: vue.js parameters


    【解决方案1】:

    router-link documentation 中,它提到 router-link 只是将“to”的内容传递给 router.push()。

    router.push() documentation 中,它提到如果您同时拥有“路径”和“参数”,则忽略参数。具体来说,它说:

    注意:如果提供了路径,则参数将被忽略,而查询则不是这种情况,如上例所示。相反,您需要提供路线的名称或使用任何参数手动指定整个路径

    因此,如果您希望使用参数,则需要使用 named route,然后在命名路由定义中构建您的路径。

    【讨论】:

      猜你喜欢
      • 2020-11-03
      • 2016-07-12
      • 2018-04-03
      • 2019-04-20
      • 1970-01-01
      • 1970-01-01
      • 2018-04-30
      • 2016-12-28
      • 1970-01-01
      相关资源
      最近更新 更多