Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript NuxtJS中具有Slug参数的未知动态嵌套路由?_Javascript_Vue.js_Vuejs2_Vue Router_Nuxt.js - Fatal编程技术网

Javascript NuxtJS中具有Slug参数的未知动态嵌套路由?

Javascript NuxtJS中具有Slug参数的未知动态嵌套路由?,javascript,vue.js,vuejs2,vue-router,nuxt.js,Javascript,Vue.js,Vuejs2,Vue Router,Nuxt.js,我仍在学习如何使用NuxtJS,我在这里的文档中看到:如果在pages文件夹中添加一个名为“wue.vue”的文件,那么如果pages文件夹中没有指定路径,那么这就是一种包罗万象的做法 这工作得很好,但我现在需要做的是能够向该文件传递一个参数。我目前正在尝试在pages/_slug/index.vue中复制的内容是: asyncData ({ params }) { return axios.get(`https://example.com/wp-json/wp/v2/pages?slu

我仍在学习如何使用NuxtJS,我在这里的文档中看到:如果在pages文件夹中添加一个名为“wue.vue”的文件,那么如果pages文件夹中没有指定路径,那么这就是一种包罗万象的做法

这工作得很好,但我现在需要做的是能够向该文件传递一个参数。我目前正在尝试在pages/_slug/index.vue中复制的内容是:

asyncData ({ params }) {
    return axios.get(`https://example.com/wp-json/wp/v2/pages?slug=${params.slug}`)
    .then((res) => {
      return {
        page: res.data[0]
      }
    })
    .catch(error => {
      console.log(error)
      this.errored = true
    })
  },
因为它在“_slug”文件夹中,所以我可以将params.slug传递给它,它工作得很好。但是我现在正试图在ue.vue文件中实现一个包罗万象的功能,但不确定在该文件中获取slug参数的最佳方法。我尝试将该函数添加到该文件中,但没有成功

有没有办法将slug参数传递到NuxtJS中的uuxE.vue文件?

使用param.pathMatch:

asyncData ({ params }) {
  return axios.get(`https://example.com/wp-json/wp/v2/pages?slug=${params.pathMatch}`)
    .then((res) => {
      return {
        page: res.data[0]
      }
    })
    .catch(error => {
      console.log(error)
      this.errored = true
    })
},