【问题标题】:nuxt how to have a question mark after the page namenuxt如何在页面名称后加问号
【发布时间】:2021-06-25 02:05:37
【问题描述】:

我有这个设置:

pages/
--| search/
-----| _index.vue

我想要一个这样的网址:

myApp.com/search/?parameter=1

但是当我在search 之后手动将?parameter=1 放入url 时,它告诉我This page could not be found。如何实现路由,以便在/ 之后我可以拥有? 而不会出现错误?

【问题讨论】:

  • 一定不要混用query stringURL params。在这里,您需要访问query string。如果您想以params 的方式使用它,您的网址将类似于/search/1

标签: vue.js nuxt.js


【解决方案1】:

这是一个干净的方法。

/pages/search-page.vue

<template>
  <div>This is the search page</div>
</template>

<script>
export default {
  name: 'SearchPage',
  mounted() {
    console.log('query >>', this.$route.query.search)
  },
}
</script>

【讨论】:

    【解决方案2】:

    将您的 _index.vue 更改为 _id.vue,这是 nuxt 默认的

    https://codesandbox.io/s/blissful-wave-cjqp7?file=/pages/search/_id.vue

    【讨论】:

    • 这行得通,但这绝对不是要走的路。
    • @kissu 我当然知道,但你明白他的问题吗?
    • 是的,我明白他的意思。我也可以看到他的页面有一些问题。不确定这是什么。看看他在这里的其他问题,看起来他正在尝试制作一些搜索功能,因此拥有_id 不是要走的路。另外,如果你知道这不是要走的路,为什么要建议呢?
    猜你喜欢
    • 2018-06-25
    • 2021-01-08
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多