【问题标题】:Drupal is not defined - jQuery (Drupal 8)Drupal 未定义 - jQuery (Drupal 8)
【发布时间】:2019-07-31 10:35:58
【问题描述】:

如果我的问题很愚蠢,我很抱歉。我的jQuery 代码仅在我以管理员身份登录时才有效。当我没有登录时,它不工作,并且我在控制台中出现错误:Drupal is not defined。

我的main.js 文件是这样的:

(function ($, Drupal, window, document, undefined) {
    $(document).ready(function(){
       code goes here
    });     
})(jQuery, Drupal, this, this.document);

mytheme.libraries.yml(我创建了一个自定义主题)看起来是这样的:

global-styling: 
  js:
    js/main.js: {}
  css:
    component:
      css/style.css: {}
  dependencies:
    - mytheme/slick

slick:
 css:
   theme:
     /libraries/slick/slick/slick.css: {}
 js:
   /libraries/slick/slick/slick.min.js: {}
 dependencies:
   - core/jquery

请帮忙。

编辑

global-styling: 
  js:
    js/main.js: {}
  css:
    component:
      css/style.css: {}
  dependencies:
    - mytheme/slick
    - core/drupal

我在依赖项中添加了 core/drupal,现在没有错误,但是当我没有登录时,jQuery 仍然无法工作。

【问题讨论】:

  • 尝试将 core/drupal 添加到您的依赖项中
  • 我现在编辑了我的帖子。添加核心/drupal 并没有完全帮助:(@BrettGregson

标签: javascript jquery drupal drupal-8


【解决方案1】:
  dependencies:
    - core/jquery
    - core/drupal

【讨论】:

    猜你喜欢
    • 2018-07-24
    • 2016-12-30
    • 2015-08-03
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 2017-10-10
    • 1970-01-01
    相关资源
    最近更新 更多