简体   繁体   English

解析错误:意外的令牌,预期的“,” JavaScript React

[英]Parsing error: Unexpected token, expected “,” JavaScript React

Am trying to pass plain javascript code inside of a component to use in index.js render.我试图在组件内部传递普通的 javascript 代码以在 index.js 渲染中使用。 The code i want to use is a text animation that also has an HTML file and CSS to go along with it.我要使用的代码是一个文本 animation,它也有一个 HTML 文件和 CSS 到 Z34D1F91FB12E514B8567A 以及它。

PS I am very new to react PS我很新反应

    update() {
    let output = "";
    let complete = 0;
    for (let i = 0, n = this.queue.length; i < n; i++) {
      let { from, to, start, end, char } = this.queue[i];
      if (this.frame >= end) {
        complete++;
        output += to;
      } else if (this.frame >= start) {
        if (!char || Math.random() < 0.28) {
          char = this.randomChar();
          this.queue[i].char = char;
        }
        output += `<span class="dud">${char}</span>`;
      } else {
        output += from;
      }
    }
    this.el.innerHTML = output;
    if (complete === this.queue.length) {
      this.resolve();
    } else {
      this.frameRequest = requestAnimationFrame(this.update);
      this.frame++;
    }
  }
  randomChar() {
    return this.chars[Math.floor(Math.random() * this.chars.length)];
  }
}
const phrases = ["Welcome,", "To My Website"];
const el = document.querySelector(".text");
const fx = new TextScramble(el);
let counter = 0;
const next = () => {
  fx.setText(phrases[counter]).then(() => {
    setTimeout(next, 800);
  });
  counter = (counter + 1) % phrases.length;
};

I keep getting the following error.我不断收到以下错误。

** Line 61:1:  Parsing error: Unexpected token, expected ","

  59 |   }
  60 | }
> 61 | const phrases = ["Welcome,", "To My Website"];
     | ^
  62 | 
  63 | const el = document.querySelector(".text");
  64 | const fx = new TextScramble(el);**

You don't show us the whole code.你没有向我们展示整个代码。 With what is here, you have an unmatched } on line 60.有了这里的内容,您在第 60 行有一个无与伦比的 }。

And you should have:你应该有:

function update () {
...
function randomChar () {
...

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

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