Using JSON.stringify to report error exports is not defined in plug-ins in vue

vue-cli Project created

utils/index.js the code is as follows

exports.install = function (Vue, options) {
    Vue.prototype.test= function () {
        JSON.stringify({})
        console.log("")
    }
};

main.js the code is as follows

import commonFun from "./utils/index"
Vue.use(commonFun)

browser exports is not defined
console export "default" (imported as" commonFun") was not found in. / utils/index"

Delete JSON.stringify , no exception!

< hr > The

problem has been solved. According to the answer @ gaoryrt , rewrite as follows: it work!

export default {
    install(Vue, options)  {
        Vue.prototype.Utils = {
            funA(o) {
                ...
            },
            funB(o) {
                ...
            }
        }
    }
}
Mar.21,2021

doesn't seem to be the problem with JSON.stringify () , but the way you use exports .
if you want to use import commonFun in main.js , then in utils/index.js you need export default
if you want to use exports.install = in utils/index.js , then main.js should use import {install}


I think it should be the configuration file in. / utils/index try this

Menu