[英]My code is right,but eslint give me a error, how does it come?
I am studying vue render funtion, this is my index.js
:我正在研究 vue 渲染功能,这是我的
index.js
:
<script>
export default {
name:'MyHead',
props:{
level:Number
},
render(h){
return h('div', [h('h'+this.level,'this is head' + this.level)])
}
}
</script>
The vscode appears some errors: vscode出现了一些错误:
Then I set javascript.validate.enable
to false
in settings.json,these errors disappear.然后我在settings.json中将
javascript.validate.enable
设置为false
,这些错误就消失了。
And I run npm run lint
to lint code, this error come:我运行
npm run lint
到 lint 代码,这个错误来了:
error: Parsing error: Unexpected token, expected "}"
How does it come?它是怎么来的? Because my
eslint
config is not right?因为我的
eslint
配置不对? Thank you in advance.先感谢您。
My devDependencies
:我的
devDependencies
:
{
"@vue/cli-plugin-babel": "^3.4.0",
"@vue/cli-plugin-eslint": "^3.4.0",
"@vue/cli-service": "^3.4.0",
"babel-eslint": "^10.0.1",
"eslint": "^7.6.0",
"eslint-plugin-vue": "^6.2.2",
"less": "^3.9.0",
"less-loader": "^5.0.0",
"mockjs": "1.0.1-beta3",
"vue-template-compiler": "^2.5.21"
}
.eslintrc.js
is .eslintrc.js
是
module.exports = {
env: {
browser: true,
es6: true,
node: true
},
extends: [
'eslint:recommended',
'plugin:vue/essential'
],
plugins: [
'vue'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
// NOTE 异步加载路由报错:Parsing error: Unexpected token import
parser: 'vue-eslint-parser',
parserOptions: {
parser: 'babel-eslint',
ecmaVersion: '2018',
sourceType: 'module'
},
rules: {
quotes: [2, 'single', { 'allowTemplateLiterals': true }],
semi: [2, 'never'],
// 强制在关键字前后使用一致的空格 (前后腰需要)
'keyword-spacing': 2,
// 强制一行的最大长度
'max-len': [1, 100],
// 使用 === 替代 == allow-null允许null和undefined==
'eqeqeq': [2, 'allow-null'],
// 禁止将变量初始化为 undefined
'no-undef-init': 2,
// 禁止将 undefined 作为标识符
'no-undefined': 0,
// 禁止出现未使用过的变量
'no-unused-vars': [2, { 'vars': 'all', 'args': 'none' }],
// 要求使用 const 声明那些声明后不再被修改的变量
'no-var': 2,
'prefer-const': 2,
'spaced-comment': [2, 'always'],
'vue/multiline-html-element-content-newline': 0,
'vue/max-attributes-per-line': [2, {
'singleline': 4,
'multiline': {
'max': 4,
'allowFirstLine': true
}
}],
'vue/html-indent': [2, 'tab', {
'attribute': 4,
'baseIndent': 1,
'closeBracket': 0,
'alignAttributesVertically': true,
'ignores': []
}],
// https://eslint.vuejs.org/rules/attributes-order.html
'vue/attributes-order': [2, {
'order': [
'DEFINITION',
'LIST_RENDERING',
'CONDITIONALS',
'RENDER_MODIFIERS',
'GLOBAL',
'UNIQUE',
'TWO_WAY_BINDING',
'OTHER_DIRECTIVES',
'OTHER_ATTR',
'EVENTS',
'CONTENT'
],
'alphabetical': false
}]
}
}
It doesn't need script
tag when use render
funtion to create a component in js file.使用
render
功能在 js 文件中创建组件时不需要script
标记。
export default {
name:'MyHead',
props:{
level:Number
},
render(h){
return h('div',[h('h'+this.level,'这是标题' + this.level)])
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.