【问题标题】:modify router meta field in Vue.js project using Gridsome使用 Gridsome 修改 Vue.js 项目中的路由器元字段
【发布时间】:2020-01-05 03:48:34
【问题描述】:

我正在尝试为 Gridsome 为我自动生成的路线指定 meta object,如下所示:

meta: {
      auth: true
    }

但是在 Gridsome 中没有普通的 routes/index.js 文件——只有一个在 index.js 中像这样暴露的路由对象:

export default function (Vue, { router, head, isClient }) 
{}

如何进入路由器并将元数据添加到我要修改的特定路由?

【问题讨论】:

  • 有什么解决办法吗?

标签: vue.js vue-router gridsome


【解决方案1】:

您可以通过this inside components script 标签获取route 对象

<script>
export default {
  created () {
    this.$route.meta = {requiresAuth: true}    
  }
}
</script>

【讨论】:

  • 我认为这不起作用“无法分配给对象 '#' 的只读属性 'meta'”
猜你喜欢
  • 2021-01-21
  • 1970-01-01
  • 2021-01-27
  • 2019-12-25
  • 1970-01-01
  • 1970-01-01
  • 2021-01-18
  • 2018-04-03
  • 2018-08-20
相关资源
最近更新 更多