【问题标题】:How to use plugin in only one component using Nuxt.js?如何使用 Nuxt.js 仅在一个组件中使用插件?
【发布时间】:2021-11-16 17:45:13
【问题描述】:

我正在用 nuxt.js 做一个简单的博客网站,我只需要在一个组件中导入编辑器,我不想使用nuxt.config.js。这是我正在尝试做的,但它似乎不起作用。

//Inside '~/plugins/vue2-editor'
import Vue from "vue";
import Vue2Editor from "vue2-editor";
Vue.use(Vue2Editor);
export default {Vue2Editor}

//Inside component
<template>
  <div class="text-editor">
    <client-only>
       <Vue2Editor/>
    </client-only>
  </div>
</template>

<script>
import {Vue2Editor} from '~/plugins/vue2-editor'
export default {
components: {
    Vue2Editor
  },
}
</script>

我该怎么办?

【问题讨论】:

  • 这可能会对你有所帮助:stackoverflow.com/questions/56805180/…
  • @tho-masn 不建议在 Vue 中使用 require
  • 否则,这个问题主要在 SO 上被问到,在这里快速搜索可以为您提供帮助。
  • 感谢提示,没看到它在使用require。

标签: vue.js nuxt.js


【解决方案1】:

如果您只想在一个组件中使用它,请在此处导入它(vue2-editor)(无需插件)。那么,您对client-only 的使用应该很好。
更多细节可以在这个其他答案中找到:How to fix navigator / window / document is undefined in Nuxt

否则,您可以使用动态导入,但我不确定您是否需要这样做:https://stackoverflow.com/a/67825061/8816585

【讨论】:

    猜你喜欢
    • 2021-11-03
    • 2018-12-19
    • 1970-01-01
    • 2021-01-21
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    • 2020-11-11
    • 2018-03-30
    相关资源
    最近更新 更多