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

时间:2018-06-27 21:46:46

标签: javascript eslint

我有这个字符串:

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

我收到陪同错误exceeds the maximum line length of...

我想将此字符串分成几行。

谢谢!

1 个答案:

答案 0 :(得分:2)

您可以仅将换行符与模板文字一起使用,但是这些换行符将显示在您的字符串中。因此,将其拆分为多行并使用字符串连接。

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

或使用带有连接的数组

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}`
相关问题