繁体   English   中英

未定义'drupalSettings'no-undef

[英]'drupalSettings' is not defined no-undef

我有一个单页应用程序,我想在特定内容类型的每个drupal节点中运行。

该应用程序是使用纱线在反应中完成的。

在我的index.js文件中,我尝试执行以下操作:

if(window.location.href !== 'http://localhost:3002/') {
  console.log(drupalSettings);
}

但是npm run buildyarn build都给了我'drupalSettings' is not defined no-undef

如何强制npm / yarn忽略此警告?

当您使用yarn或类似的东西时,您需要让eslint知道该变量来自全局范围。 eslint文档

/*global someFunction b:true*/
/*eslint no-undef: "error"*/

var a = someFunction();
b = 10;

其中b:true表示可以在此文件的范围内更改b 对于诸如drupalSettings之类的:true可能是可选的,因为您最有可能从页面中获取信息而不进行任何设置。

对于您的特定用途,您将使用

/*global drupalSettings:true*/
/*eslint no-undef: "error"*/

console.log(drupalSettings)

然后您将在浏览器的控制台中看到输出。

暂无
暂无

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

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