vue.js - NuxtJs 在每条路线导航上附加查询参数
问题描述
我有一个查询字符串,我需要将其附加到每个路由,以便当我单击链接时,它会抓取查询字符串并将其附加到 URL。这样,当我执行 to="route" 之类的操作时,它会自动将我的查询字符串附加到 URL。
当我单击一次时,我已经开始工作了,但是当我双击任何东西时,它会爆炸并出现以下错误
“TypeError:第一个参数必须是字符串、Buffer、ArrayBuffer、Array 或类似数组的对象”。
我每次在我的控制台中也看到这个错误,只是没有在页面上,所以我想我没有正确地做某事。
在我的default.vue
页面中,我有以下内容:
<script>
export default {
components: {
// all the components I am using on this page
},
data: () => {
return {
landingRoute: '',
}
},
fetch() {
if (this.isEmpty(this.$route.query)) {
const landingKey = this.landingRoute
this.$router.push({
name: this.$router.name,
query: { info: landingKey },
})
}
},
watch: {
'$route.query': '$fetch',
},
beforeMount() {
this.landingRoute = this.$route.query.info
},
methods: {
isEmpty(json) {
return Object.keys(json).length === 0
},
},
}
</script>
错误发生在 client.js 堆栈跟踪看起来像这样......
"TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object".
at fromObject (index.js?b639:139)
at from (index.js?b639:137)
at Function.Buffer.from (index.js?b639:149)
at eval (sessionLog.js?d88f:14)
at promisfiy (utils.js?ebed:291)
at middlewareSeries (utils.jseed:291)
at Vue.callMiddlewear (client.js?06a0:267)
at Vue._calle6$ (client.js05a0:267)
at tryCatch (runtime.js?96cf:63)
at Generator.invoke [as _invoke] (runtime.js?96cf:294)
这是我的沙箱 https://codesandbox.io/s/nuxtjs-vuetify-forked-wrs2s?file=/layouts/default.vue
解决方案
推荐阅读
- android - 何时调用 onCreateViewHolder,为什么?回收站视图
- python - Python - 获取给定坐标的图形方程
- php - 这是 googleassitant 和 PHP 之间的 webhook 的 url
- javascript - 什么决定了javascript类型转换顺序?
- c# - 复制通用流而不更改位置
- haskell - 在 http 请求之间保持状态
- vidyo - 管理员用户退出时结束 vidyo.io 会议
- apache - 简单的 .htaccess 重定向导致无限循环
- python - 被抓取的网站需要人工导航(无需登录)
- php - 如何修改从sql表中读取的行