Javascript 模板文字 需要反引号,而不是直接引号。
您需要使用反引号(也称为“重音符”-您会在1键旁边找到)-而不是单引号-来创建模板文字。
反引号在许多编程语言中都很常见,但可能对Javascript开发人员来说是新的。
范例 :
categoryName="name";categoryElements="element";console.log(`categoryName: ${this.categoryName}ncategoryElements: ${categoryElements} `)输出 :
VM626:1 categoryName: name categoryElements: element



