【问题标题】:How to properly write a vuepress plugin?如何正确编写 vuepress 插件?
【发布时间】:2019-04-06 08:51:38
【问题描述】:

我正在尝试编写一个 Vuepress 插件以利用 App Level 增强功能并安装一个 Vue 插件。但我似乎无法让它发挥作用。你能看看下面的代码,看看有什么问题吗?


{.vuepress/config.js}
module.exports = {
  plugins: [
    require('./builder.plugin.js')
  ]
}

{.vuepress/builder.plugin.js}
module.exports = (option, ctx) => {
  return {
    enhanceAppFiles: [{
      name: 'builder-plugin',
      content: `export default ({ Vue }) => {
        Vue.component('b-header', {
          name: 'b-header',
          template: '<div id="header"><slot /></div>'
        })
      }`
    }]
  }
}

{README.md}
# Introduction
<b-header>Test from component</b-header>

我得到的最后一个错误是:

Unknown custom element: <b-header> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

【问题讨论】:

    标签: javascript vue.js vue-component vuepress


    【解决方案1】:

    我真的找到了答案。以上方法不起作用,因为我使用插件将客户端站点代码与运行时代码混合在一起。

    诀窍是使用enhancedAPP hook。 参考:https://vuepress.vuejs.org/guide/basic-config.html#theme-configuration

    【讨论】:

    猜你喜欢
    • 2020-07-22
    • 2019-04-12
    • 2019-04-23
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多