plus(xxx) is not defined
前言
最近在寫html5+app項目時 遇到一個plus很坑的問題 明明寫好了plusready 而且plus能正常打印 plus的api也能正常使用
但是!!!就是報plus is not defined !!!
思來想去 應該不是代碼的問題 應該是環境的問題
果不奇然 問題出在Eslint。
以下是解決方法
一、在根目錄下創建文件.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