【问题标题】:Nuxt getting query parameterNuxt 获取查询参数
【发布时间】:2020-06-08 02:47:04
【问题描述】:

我正在尝试从

获取 q 参数
http://localhost:3000/search?q=myterms

但是,我似乎无法弄清楚为什么它会给我一个错误

无法读取未定义的属性“q”

<template>
 <div class="container">
  <h1>Hello</h1>
  Query: {{ query }}
 </div>
</template>

<script>
  export default {
    watchQuery: ['q'],
    name: 'Search',
    computed: {
      query() {
        return this.$route.params.query.q
      }
    }
  }
</script>

<style></style>

任何帮助将不胜感激!谢谢

【问题讨论】:

    标签: nuxt.js


    【解决方案1】:

    $route.params 用于路由参数url/&lt;param&gt;,$route.query 用于查询字符串参数url?q=&lt;value&gt;

    computed: {
        query() {
          return this.$route.query.q
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2021-02-14
      • 1970-01-01
      • 2016-11-24
      • 2017-02-01
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      • 2014-12-26
      相关资源
      最近更新 更多