繁体   English   中英

如何在 nuxt.js 中安装 Vue 包

[英]How to Install Vue Packages in nuxt.js

我正在尝试在我的 Nuxt js 应用程序中安装Vue Typer ,但没有成功。 我不断收到“文档未定义”。 我尝试将它作为插件导入到我的 nuxt.config.js 中,但它不起作用。

我让它在我的 VueCLI 3 中工作,似乎用这种方法工作得很好。

欣赏它!

得到

NuxtServerError render function or template not defined in component: anonymous

 ////plugins/// import Vue from vue; if (process.client) { const VueTyper = require('vue-typer'); Vue.use(VueTyper); } ///nuxt.config.js/// plugins: [ {src: '~/plugins/vue-typer.js', ssr: false} ],
 <template> <vue-typer text='Hello World! I was registered locally!'></vue-typer> </template> <script> const VueTyper = processs.client ? require('vue-typer'): ''; export default { components: { VueTyper } } </script>

要解决此问题, vueTyper.client.js在插件文件夹下创建一个名为vueTyper.client.js文件,然后键入以下内容;

import Vue from 'vue';
import { VueTyper } from 'vue-typer';

Vue.component('vue-typer', VueTyper);

然后在您的nuxt.config.js添加到您的插件中

plugins: [
  '~/plugins/vueTyper.client.js'
]

执行此操作后,您可以轻松地在应用程序中的任何位置使用它而不会出错:

<vue-typer text='Hello World! I was registered locally!'></vue-typer>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM