当前位置:网站首页>Eslint syntax error is solved
Eslint syntax error is solved
2022-08-01 15:01:00 【Bitter Sea 123】
Added a previous project todayeslint,Found a lot of variable errors,But there is nothing wrong with double-checking your code,According to the error message, it can be seen that it is someapi在eslintCaused by irregular use of syntax,大概总结如下:
1.setup中接收props
报错:Getting a value from the props in root scope of setup() will cause the value to lose reactivity
之前写法:
setup(props) {
const {
option } = props
}
eslint写法
setup(props) {
const {
option } = {
...props
}
}
2.Iterate over an array(forEach代替map),map要求有返回值
报错:Array.prototype.map() expects a return value from arrow function array-callback-return
之前写法:
row.childrens.map((pit) => {
pit.childs.map((cit, ci) => {
if (cit.n_id === item.n_id) {
pit.childs.splice(ci, 1)
}
})
})
eslint写法:
row.childrens.forEach((pit) => {
pit.childs.forEach((cit, ci) => {
if (cit.n_id === item.n_id) {
pit.childs.splice(ci, 1)
}
})
})
3.whitespace correction
Previous items may not match in indentationeslint语法,此时只需 npm run lint The code can be automatically corrected,It is recommended to get the project in hand beforenpm run lint,After modifying other syntax errors,In this way, you will find that syntax errors will be much less,便于查找修改.
4.解构赋值
eslintDestructuring assignment is recommended,Some need to use structure assignment to get variables,如:
之前写法:
const data = props.data
eslint中写法
const {
data } = props
5.switch-casein the conditional statementdefault
Add to the last conditiondefault
之前写法:
switch (sease) {
case '1':
case '2':
case '3':
console.log('春季')
break;
case '4':
case '5':
case '6':
console.log('夏季')
break;
case '7':
case '8':
case '9':
console.log('秋季')
break;
default:
console.log('冬季')
break;
}
6.最后一个importLeave blank lines after import
报错:.Expected 1 empty line after import statement not followed by another import import/newline-after-import
之前写法:
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
eslint写法:
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
7.Template strings instead of concatenated strings
报错:Unexpected string concatenation prefer-template
之前写法:
<p>{
{
info.day + '天'}}<p>
eslint写法:
<p>{
{
`${
info.day}天`}}<p>
8.不使用for循环
之前写法:
for (let i = 0;i < arr.length; i++) {
console.log(arr[i])
}
eslint写法:
arr.forEach((item) => {
console.log(item)
})
提示:本文图片等素材来源于网络,若有侵权,请发邮件至邮箱:[email protected]联系笔者 删除.
笔者:苦海
边栏推荐
- pytorch测试的时候为何要加上model.eval()?
- LeetCode50天刷题计划(Day 11—— 最接近的三数之和(8.40-10.00)
- what is tail tooth feast
- HTB-Shocker
- ffmpeg视频剪辑中报错Could not write header for output file #0 (incorrect codec parameters ?): ……
- flink-sql 可以单独配置某个算子节点的并行度吗?
- Pytorch - Distributed Model Training
- 我寻找的方向
- SQL查询数据以及排序
- 有谁知道pg12.5版本的数据库驱动在哪里能找到么?
猜你喜欢

经纬信息IPO过会:年营收3.5亿 叶肖华控制46.3%股权

MySQL中的时区设置

Amperon IPO meeting: annual revenue of 500 million Tongchuang Weiye and China Mobile Innovation are shareholders

股票策略02 | 技术择时+行业因子+市值轮动

轮询和长轮询的区别

透过现象看本质,如何针对用户做好需求分析

产品力无提升的雷克萨斯新款ES ,为何敢于涨价?

Range query based on date in MySQL

Kernel pwn 入门 (6)

openEuler 社区12位开发者荣获年度开源贡献之星
随机推荐
Performance Optimization - Rendering Optimization Notes
MySQL中的行锁
The soul asks: How does MySQL solve phantom reads?
MySQL查询上的问题
五分钟带你上手ShardingJDBC实现MySQL分库分表
Distributed database problem (1): data partition
qt 通用ui
lombok builder重写
Range query based on date in MySQL
2022年5月20日最全摸鱼游戏导航
到底什么才是真正的商业智能(BI)
what is tail tooth feast
redis主从同步方式(redis数据同步原理)
math.pow()函数用法[通俗易懂]
Amperon IPO meeting: annual revenue of 500 million Tongchuang Weiye and China Mobile Innovation are shareholders
Grid布局 容器属性(一) `grid-template`系列属性
RepOptimizer学习笔记
ffmpeg视频剪辑中报错Could not write header for output file #0 (incorrect codec parameters ?): ……
LeetCode50天刷题计划(Day 11—— 最接近的三数之和(8.40-10.00)
tkinter-TinUI-xml实战(6)问卷