由于 eslint 错误拆分字符串

split string because of eslint error

我有这个字符串:

`${this.new_post.type_to_send}-${this.new_post.france_service}-${this.new_post.service_web}`

我收到一个 eslint 错误 exceeds the maximum line length of...

我想把这个字符串分成几行。

谢谢!

您可以只对模板文字使用换行符,但这些换行符会显示在您的字符串中。所以将它分成多行并使用字符串连接。

const str = `${this.new_post.type_to_send}-` + 
            `${this.new_post.france_service}-` +
            `${this.new_post.service_web}`

或使用数组与 join

const str = [this.new_post.type_to_send, 
            this.new_post.france_service,
            this.new_post.service_web].join('-')

或者如果你的行长度不是太短,使用变量来摆脱重复的嵌套代码。

const p = this.new_post
const str = `${p.type_to_send}-${p.france_service}-${p.service_web}`