【问题标题】:Unexpected template string expression in Vue.jsVue.js 中意外的模板字符串表达式
【发布时间】:2016-12-12 03:32:46
【问题描述】:

每次我像这样 ${row.name} 编码时,我都会收到此错误“eslint.org/docs/rules/no-template-curly-in-string Unexpected template string expression”。

有什么帮助吗?

【问题讨论】:

标签: javascript vue.js


【解决方案1】:

ES6 模板字符串应该与反引号一起使用,而不是单引号。 替换这个:

'delete the item ${row.name}'

有了这个:

`delete the item ${row.name}`

这是 cmets 中要求的 ESLint 示例:http://eslint.org/docs/rules/no-template-curly-in-string#examples

【讨论】:

    【解决方案2】:

    如果您没有使用 ES6 模板字符串并且实际上希望将美元符号打印到屏幕上,请将以下内容放在字符串声明的上方。

    /* eslint-disable no-template-curly-in-string */
    

    【讨论】:

      【解决方案3】:

      有时需要在字符串中使用模板字符, 比如里面的锚标签等等。

      '<a href="${' +
      'OrganizationInfo.PrivacyPolicy}" target="_blank" >Privacy Policy</a>'
      

      断开字符串对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-16
        • 2015-07-03
        • 2018-01-02
        • 1970-01-01
        • 1970-01-01
        • 2021-02-20
        相关资源
        最近更新 更多