最近很多小伙伴再写项目时,会遇到一个plus很坑的问题:明明而且plus能正常打印 plus的api也能正常使用,但是就是报”plus is not defined“以下是解决方法:
一、在根目录下创建文件.eslintrc
二、复制默认代码到.eslintrc文件里
{ "extends": [ "eslint:recommended", "plugin:import/errors", "plugin:import/warnings" ], "plugins": [ "react" ], "parserOptions": { "ecmaVersion": 6, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "env": { "es6": true, "browser": true, "node": true, "jquery": true, "mocha": true }, "settings": { "import/ignore": [ "node_modules" ] }, "rules": { "no-unused-vars": "off", "no-console": "off", "no-debugger": "off", "no-mixed-spaces-and-tabs": "off" } }
三、把‘plus’加到文档中去
不一定是‘plus’ 、如果觉得not defined报错都可以放进去
"globals":{ "plus": true, }
也就是说 .eslintrc的代码如下:
{ "extends": [ "eslint:recommended", "plugin:import/errors", "plugin:import/warnings" ], "plugins": [ "react" ], "parserOptions": { "ecmaVersion": 6, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "env": { "es6": true, "browser": true, "node": true, "jquery": true, "mocha": true }, "settings": { "import/ignore": [ "node_modules" ] }, "rules": { "no-unused-vars": "off", "no-console": "off", "no-debugger": "off", "no-mixed-spaces-and-tabs": "off" }, "globals":{ "plus":true } }
四、在package.json文件里面配置scripts的lint属性
"scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject", "link":"eslint src" },
五、运行检测
npm lint 或者 npm run lint
六、重启项目
完工!
以上就是关于“出现plus is not defined问题的解决方法”的相关解答,若有不清楚的可以咨询酷番云,酷番云作为云南为数不错持有ICP/ISP/IDC等资质专业云计算提供商之一7*24小时不间断售后运维技术支持,专业备案团队全力支持。
云服务器ECS地址:https://www.kufanyun.com/server/