将 npm 包导入 nuxt 应用程序 [英] Import npm package to nuxt appliction

查看:89
本文介绍了将 npm 包导入 nuxt 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于 SEO 的原因,我不得不使用 Nuxt 重建我的 vuejs 应用程序.

For SEO Reasons i had to rebuild my vuejs app with Nuxt.

如何在nuxt app中导入npm包?

How can you import npm packages in nuxt app?

就像在 vue.js 中一样,您只需将下面的代码添加到 APP.vue

like in vue.js you simply add the code below to APP.vue

import InfiniteLoading from 'vue-infinite-loading'
vue.use(InfiniteLoading)

推荐答案

在插件文件夹中创建新文件 infinite-loading.js

create new file in plugin folder infinite-loading.js

import vue from "vue"
import InfiniteLoading from 'vue-infinite-loading'
vue.use(InfiniteLoading)

nuxt.config.js 中将你的文件名包含在插件数组中

in nuxt.config.js include your file name in plugin array

  plugins: [
    '@/plugins/infinite-loading',
  ],

然后重启服务

这篇关于将 npm 包导入 nuxt 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆