【ESLint】error Unexpected string concatenation prefer-template

219 阅读1分钟

初始写法:

const height = 32 * i + 'px'

错误提示: error  Unexpected string concatenation  prefer-template

原因:ESLint推荐用ES6的Template String(模版字符串)来拼接字符串,而不能用+号。

解决方案:

`我是字符串部分,${我是参数部分},我是字符串部分`

正确写法:

const height = `${ 32 * i }px`