【发布时间】:2020-03-12 01:45:46
【问题描述】:
我正在使用 vuejs 和 vue router,我正在使用 axios 根据我在 router/index.js 文件中设置的路由向 API 发出 get 请求。
但是我想传递 SEO 友好的标题而不是 id。
myname/products/bears 而不是myname/products/1
路线
{
path: '/products/:id',
name: 'productDetail',
props: true,
component: function () {
return import('../views/products/mycomponent')
}
},
方法
getProduct(){
var itemId = this.$route.params.id;
//return console.log(itemId)
axios
.get('http://localhost:3000/products/'+itemId)
.then(response => (
this.server = response.data
))
},
【问题讨论】:
-
这能回答你的问题吗? How to build SEO-friendly routes in NuxtJS?
标签: vue.js