首页 > 解决方案 > 如何在 Nuxt 中访问路由器查询

问题描述

我想在我的 URL 中传递一个值参数,我的挂载是这样的

  mounted () {
    this.$router.push({
      path: '/activatewithphone',
      query: { serial: this.$route.params.serial, machine: this.$route.params.machine }
    })
  },

我的计算

  computed: {
    serial () {
      return this.$route.query.serial
    },
    machine () {
      return this.$route.query.machine
    }
  },

我得到这样的序列和机器值

this.serial and this.machine

这里的问题是当用户访问这样的 URL

example.com/activatewithphone?serial=sddsdsds&machine=sdsdsd

它重定向回example.com/activatewithphone

串口和机器是动态的

当我试图用this.serial and this.machine

它回来了undefine

该应用程序的总体思路是

就是这样,用户单击桌面上的链接以激活他的帐户,桌面应用程序包含 URL 的参数(串行和机器)并启动浏览器,用户输入表单编号并在网络上付款。然后我将参考代码与随 URL 一起发送的序列号和机器发送回后端。现在清楚了吗?

标签: javascriptvue.jsnuxt.js

解决方案


好吧,所以这基本上是一个错字。

OP 使用this.$route.params.serial而不是this.$route.query.serial.


推荐阅读