【问题标题】:Passing SEO friendly title instead of an ID number in Vue在 Vue 中传递 SEO 友好的标题而不是 ID 号
【发布时间】:2020-03-12 01:45:46
【问题描述】:

我正在使用 vuejsvue 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
            ))
        },

【问题讨论】:

标签: vue.js


【解决方案1】:

要回答您的问题,我认为这更多的是数据问题?如果您的 id 是 bears,它将按您的意愿工作。如果您提供名称 bears 的字段也是唯一的,您可以使用它来代替 url 中的 id。

附带说明:VueJS 本身无法提供对 SEO 友好的元数据,您可能需要考虑使用 Gridsome 或 Nuxt 之类的东西。

【讨论】:

  • 谢谢,我可以将其作为产品/熊/uniqueID 发送
猜你喜欢
  • 2015-01-31
  • 2021-12-07
  • 2011-11-02
  • 1970-01-01
  • 2013-03-11
  • 2012-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多