简体   繁体   English

由于eslint错误而分割了字符串

[英]split string because of eslint error

i have this string: 我有这个字符串:

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

i'm receiving an eslint error exceeds the maximum line length of... 我收到eslint错误, exceeds the maximum line length of...

I would like split this string in severals lines. 我想将此字符串分成几行。

Thank you! 谢谢!

You could just use line feeds with the template literal, but those line feeds would show up in your string. 您可以仅将换行符与模板文字一起使用,但是这些换行符将显示在字符串中。 So split it to multiple lines and use string concatenation. 因此,将其拆分为多行并使用字符串连接。

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

or use an array with join 或结合使用数组

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

or if you line length is not too short, use a variable to get rid of the repeated nested code. 或者,如果行长不是太短,则使用变量来摆脱重复的嵌套代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM