vue.js - Nuxt.js 为自定义插件返回未定义
问题描述
我想在 Nuxt.js 中为本地数据库创建一个自定义插件,在完成代码后,我在 nuxt.config.js 中注册了它,但它不起作用。所以我尝试了文档上的示例代码,看看我做错了什么,问题是,示例代码也不起作用。这是我注册它的方式:
插件/hello.js
export default ({ app }, inject) => {
inject("hello", msg => console.log(`Hello ${msg}!`));
};
nuxt.config.js
module.exports = {
ssr: false,
target: "static",
head: {
title: "project-title",
meta: [{ charset: "utf-8" }],
},
loading: false,
plugins: [{ ssr: true, src: "@/plugins/icons.js" }, "@/plugins/hello.js"],
modules: ["@nuxtjs/axios", "@nuxtjs/auth-next"],
}
每当我尝试使用this.$hello("something")
时,Nuxt 都会返回this.$hello 不是函数
解决方案
Hmm, got it. After deleting and reinstalling node_modules it's resolved, then I tried changing the name of the plugin file, after then build failed from ./node_modules/@nuxt/webpack/node_modules/babel-loader/lib/index.js
. After reinstalling packages again (deleted .nuxt, node_modules and lock file) issue is resolved.
推荐阅读
- c++ - 如何通过悬停光标来获取 UIAutomationElement 的 NamePropertyId?
- python - 'string.format' 是否允许对迭代/字典进行更多控制?
- google-cloud-dataproc - GCP Dataproc:通过 Yarn Cluster 直接使用 Spark
- python - Python:如何在数据帧中使用 sklearn 函数?
- reactjs - 如何在 google-map-react 中显示谷歌地图标记
- sql - 按加入日期分组 + 在 sql 中添加月份
- python - KeyError:将列中的日期转换为日期时的时间戳
- flutter - Flutter-如何从 Stream 中获取最后一个值
没有 RxDart? - sql-server - 为什么我的更新查询实际上没有更新?
- python - 熊猫在列之间找到具有相反值的重复项