javascript - 如何在 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 一起发送的序列号和机器发送回后端。现在清楚了吗?
解决方案
好吧,所以这基本上是一个错字。
OP 使用this.$route.params.serial
而不是this.$route.query.serial
.
推荐阅读
- html - 'border' 使 'background-color' 的工作方式不同
- swiftui - GeometryReader 大小作为子视图
- reactjs - 如何在 div 上更改类时更改 @emotion/style 样式
- sql - 每次使用随机子选择进行 SQL 更新,为所有行提供相同的值
- r - R:使用 %to% 的逻辑
- r - 从 POSIXct 对象中提取 AM/PM 列?
- spring-boot - Spring webflux Jaxb2XmlEncoder Java 11 无法识别@XMLRootElement
- firebase - 需要帮助解决未定义的类 FireBaseUser
- azure - 有人可以告诉我为什么 Azure Pipelines 不喜欢这个 yaml 文件吗?
- reactjs - 在 React 中,使用 TypeScript,我如何将道具转发给作为道具传递的组件?