当前位置:网站首页>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]联系笔者 删除.
笔者:苦海
边栏推荐
猜你喜欢

May 20, 2022 The most complete fish game navigation

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

LeetCode50天刷题计划(Day 8—— 盛最多水的容器(23.00-1.20)

LeetCode50天刷题计划(Day 7—— 字符串转换整数 (atoi) 12.20-15.20)

The soul asks: How does MySQL solve phantom reads?

ThreadLocal保存用户登录信息

MySQL中的存储过程(详细篇)

The role of the final keyword final and basic types, reference types

LeetCode50天刷题计划(Day 6—— 整数反转 14.20-15.20)

gconf/dconf编程实战(1)gconf和dconf介绍
随机推荐
js判断是pc端还是移动端(包括ipad)
到底什么才是真正的商业智能(BI)
pwnhome 个人博客快速索引(持续更新)
沃文特生物IPO过会:年营收4.8亿 养老基金是股东
The soul asks: How does MySQL solve phantom reads?
0-1背包问题的一维数组优化解析
“查找附近的商铺”|Geohash+MySQL实现地理位置筛选
数据抽取过滤的时候,数据库字段update_at类型是timestamp,抽取T-1日数据这个变量条
gconf/dconf编程实战(1)gconf和dconf介绍
信息录入率百分百上海强化施工现场建筑工人实名制管理
MySQL查询上的问题
HDU 2602: Bone Collector ← 0-1背包问题
VIM实用指南(0)基本概念与初次体验
RepOptimizer学习笔记
LeetCode50天刷题计划(Day 11—— 最接近的三数之和(8.40-10.00)
HTB-Shocker
Pytorch - Distributed Model Training
兆骑科创科创赛事平台,创业赛事活动路演,线上直播路演
MySQL中根据日期进行范围查询
stm32l476芯片介绍(nvidia驱动无法找到兼容的图形硬件)