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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36724-2ad5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36724-2ad5b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?