Javascript 如何从路由参数中获取值并将其保存在Nuxtjs中的数据中

Javascript 如何从路由参数中获取值并将其保存在Nuxtjs中的数据中,javascript,vue.js,nuxt.js,Javascript,Vue.js,Nuxt.js,比如我有这个 mounted () { this.$router.push({ path: '/activatewithphone', query: { serial: this.$route.params.serial, machine: this.$route.params.machine } }) }, 这意味着每当用户访问这样的URL时 http://example.com/activate?serial=sddsdsds&m

比如我有这个

  mounted () {
    this.$router.push({
      path: '/activatewithphone',
      query: { serial: this.$route.params.serial, machine: this.$route.params.machine }
    })
  },
这意味着每当用户访问这样的URL时

  http://example.com/activate?serial=sddsdsds&machine=sdsdsd
用户将不会看到404页面

串行和机器的值是动态的,可以是任何值

我的问题是,有没有一种方法可以获取这些值并将其数据存储在内存中

e、 g


我可以使用
this.serial

将值分配给my serial和email变量吗?您可以使用
computed属性

计算:{
序列号(){
返回此。$route.query.serial
},
电子邮件(){
返回此邮件。$route.query.email
}
}

使用计算或创建的钩子,然后使用
this.serial=this.$routes.params.serial
分配值。谢谢您的帮助,但不知何故,它向我显示了这些值是未定义的。如果用户打开“`没有
serial
值,那么它将是
undefined
,您可以像这样设置serial的初始值:
返回此值。$route.query.serial | | |“DEFAULT_serial__value”
example.comn/activatewithphone?serial=sdds&email=sdsd序列和电子邮件没有定义。问题是当用户访问
example.com/activatewithphone?serial=sdds&email=sdsd
时,会清除参数并显示
example.com/activatewithphone
  data: () => {
    return {
      serial: '',
      email: '',
    }
  },