To avoid multiple vue files referencing js files through import, global variables are defined, such as vue importing utils for global use
utils/index.js
/* eslint-enable */
const utils = {
getName: function(name) {
return name
},
}
export default utils
// const getName = fnction (name) {
// return name
// }
// export { getName }
Copy the code
vue.config.js
Module. exports = {return {utils plugins: [new webpack.ProvidePlugin({// 1. Export default: [path.resolve(__dirname, 'SRC /utils/index.js'), 'default'] path.resolve(__dirname, 'src/utils/index.js') }), ] } } }Copy the code
.eslintrc.js
{
globals: {
utails: 'readonly' / / or true}}// Set it to readonly because we are not overwriting LoDash, just calling its methods.
Copy the code
Page using
utils.getName(Macabaca)
Copy the code