当前位置:网站首页>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]联系笔者 删除.
笔者:苦海
边栏推荐
猜你喜欢
MySQL中根据日期进行范围查询
如何使用 Mashup 技术在 SAP Cloud for Customer 页面嵌入自定义 UI
龙口联合化学通过注册:年营收5.5亿 李秀梅控制92.5%股权
透过现象看本质,如何针对用户做好需求分析
Wovent Bio IPO: Annual revenue of 480 million pension fund is a shareholder
Amperon IPO meeting: annual revenue of 500 million Tongchuang Weiye and China Mobile Innovation are shareholders
SQL每日一练(牛客新题库)——第3天: 条件查询
百图生科卓越开发者计划全面升级暨《计算免疫问题白皮书》发布
LeetCode50天刷题计划(Day 11—— 最接近的三数之和(8.40-10.00)
商业智能BI业务分析思维:供应链分析 - 什么是牛鞭效应(一)
随机推荐
什么是闭包?
如何快速将Zabbix5.0升级至6.0?
openEuler 社区12位开发者荣获年度开源贡献之星
游戏元宇宙发展趋势展望分析
php gui 框架 demo
线性代数的简单应用
在网站页脚增加几只戏水的小鱼
有限合伙人与普通合伙人的区别
Amperon IPO meeting: annual revenue of 500 million Tongchuang Weiye and China Mobile Innovation are shareholders
Range query based on date in MySQL
docker部署mysql并修改其占用内存大小
30分钟成为Contributor|如何多方位参与OpenHarmony开源贡献?
redis主从同步方式(redis数据同步原理)
倪光南:openEuler已达国际同类社区水准
CodeForces 570D Tree Requests
Spark: Cluster Computing with Working Sets
“查找附近的商铺”|Geohash+MySQL实现地理位置筛选
给网站增加离开页面改变网站标题效果
Chat technology in live broadcast system (8): Architecture practice of IM message module in vivo live broadcast system
gconf/dconf实战编程(3)利用dconf库读写配置实战以及诸多配套工具演示