【问题标题】:Octal literals are not allowed in strict mode严格模式下不允许使用八进制文字
【发布时间】:2016-08-21 02:29:03
【问题描述】:

我正在使用 Angular 2。

当我在 SCSS 文件中使用它时,它运行良好。

.text::after {
  content: "\00a0\00a0";
}

但是,当我将它移入时

styles: [``]

它显示:

Uncaught SyntaxError: Octal literals are not allowed in strict mode.

我知道styles: [``] 中的代码必须是 CSS 代码。

我试过了

styles: [`
    .text::after {
      content: "  ";
    }
`]

然后屏幕直接显示  。怎么写正确?

【问题讨论】:

    标签: javascript css angular


    【解决方案1】:

    \00a0的值有问题,因为不是八进制数(八进制字符为0-7),而是十六进制数,所以用这个:

    .text::after {
      content: "\x00a0\x00a0";
    }
    

    【讨论】:

      【解决方案2】:

      或者你可以在\之前添加u(unicode)

        .text::after {
          content: "\u00a0\u00a0"
        }
      

      【讨论】:

        【解决方案3】:

        你需要逃避它

        .text::after {
          content: "\\00a0\\00a0";  // now it's just a simple plain string
        }
        

        "use strict" 是 JavaScript 1.8.5(ECMAScript 版本 5)中引入的新功能。

        其中,

        • 不允许使用八进制数字文字
        • 不允许使用转义字符
        • see more...

        【讨论】:

        猜你喜欢
        • 2021-03-31
        • 2021-08-18
        • 1970-01-01
        • 2014-06-29
        • 2018-11-11
        • 1970-01-01
        • 1970-01-01
        • 2021-08-29
        • 2016-03-25
        相关资源
        最近更新 更多