我目前尝试使用webpack.ProvidePlugin,但似乎加载不正确。这是我的environment.js
文件。
var webpack = require("webpack");
const { environment } = require("@rails/webpacker");
const vueLoader = require("./loaders/vue");
environment.loaders.append("vue", vueLoader);
environment.plugins.append(
"Provide", // arbitrary name
new webpack.ProvidePlugin({
Vue: "vue",
_: "lodash"
})
);
module.exports = environment;
还有我的文件Header.vue
<h1>{{_.capitalize(title)}} </h1>
错误:
vue.runtime.esm.js:587 [Vue warn]: Property or method "_" is not defined on
the instance but referenced during render. Make sure that this property is
reactive, either in the data option, or for class-based components, by
initializing the property.
ProvidePlugin
的整个目的是为了全局提供这些值,我对导入没有问题,只是有点不方便,某些常用模块不应该遍布整个存储库。 - user2167582