Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.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
Vue.js Nuxt生成动态路由路径_Vue.js_Wp Api - Fatal编程技术网

Vue.js Nuxt生成动态路由路径

Vue.js Nuxt生成动态路由路径,vue.js,wp-api,Vue.js,Wp Api,我正在用wpapi创建一个站点。我所有的页面都在里面: -页数 --_鼻涕虫 如果我的页面slug是site.com/about -页数 --关于 Nuxt将像这样生成html。但是如果我的路径是site.com/company/about 我可以创建这个路由吗 PS:我正在使用WordPressAPI来实现这一点。因此,如果我的页面有父页面,那么路径是:site.com/parent/child您可以使用routes键在numxt.config.js中执行此操作 文件如下: 简而言之,

我正在用wpapi创建一个站点。我所有的页面都在里面:

-页数
--_鼻涕虫
如果我的页面slug是site.com/about


-页数
--关于
Nuxt将像这样生成html。但是如果我的路径是site.com/company/about

我可以创建这个路由吗


PS:我正在使用WordPressAPI来实现这一点。因此,如果我的页面有父页面,那么路径是:site.com/parent/child

您可以使用
routes
键在
numxt.config.js
中执行此操作

文件如下:

简而言之,您可以在
numxt.config.js
中编写一个函数:
generate.routes
为您生成页面

下面是一个示例:
numxt.config.js

const axios = require('axios')

module.exports = {
  ...
  generate: {
    routes: function () {
      return axios.get('https://your-wordpress-api/')
      .then((res) => {
        return res.data.map((page) => {
          let route = '/whatever/you/like/' + page.slug
        })
      })
    }
  }
}
一些提示:

  • 您可以添加有效负载以稍微加快速度:
  • 如果需要发出大量请求,请使用
    axios.spread