如何销毁 mmenu 插件

huangapple go评论43阅读模式
英文:

How can I destroy the mmenu plugin

问题

我有一个使用Mmenu插件制作的菜单。我在小于1025px的分辨率下初始化它。我在resize内部进行初始化。我需要在大于1025的权限下销毁mmenu,以便显示通常的桌面菜单。现在我的问题是,控制台中出现错误 - 无法读取未定义的属性(读取“destroy”)。我该如何解决这个问题?

$(window).resize(function(e) {
  if ($(window).width() < 1025) {

    $menu.mmenu({
      "offCanvas": {
        "position": "left"
      },
      "navbar": {
        "title": ""
      },
      "theme": "light"
    });

    const api = $menu.data("mmenu");

  } else if ($(window).width() > 1025) {
    const api = $menu.data("mmenu");
    api.destroy();
  }
});

注意:这是代码部分的翻译,不包括代码本身。

英文:

I have a menu which is made using the Mmenu plugin. I initialize it at resolutions less than 1025px. I initialize inside resize. I need to destroy mmenu on permissions greater than 1025 so that the usual desktop menu is displayed. Now my problem is that I have an error in the console - Cannot read properties of undefined (reading 'destroy'). How can I solve this problem?

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(window).resize(function(e) {
  if ($(window).width() &lt; 1025) {

    $menu.mmenu({
      &quot;offCanvas&quot;: {
        &quot;position&quot;: &quot;left&quot;
      },
      &quot;navbar&quot;: {
        &quot;title&quot;: &quot;&quot;
      },
      &quot;theme&quot;: &quot;light&quot;
    });

    const api = $menu.data(&quot;mmenu&quot;);

  } else if ($(window).width() &gt; 1025) {
    const api = $menu.data(&quot;mmenu&quot;);
    api.destroy();
  }
});

<!-- end snippet -->

答案1

得分: 1

这可能是因为,当您尝试访问属性(destroy())时,其中包含未定义,并且尚未分配一个值。有可能destroy()是一个箭头函数,而值或函数将在稍后分配。

英文:

This could be because, when you try to access a property (destroy()), it has undefined in it and hasn't been assigned a value. It is possible that destroy() is an arrow function and that a value or function is to be assigned later.

huangapple
  • 本文由 发表于 2023年3月3日 19:20:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75626424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定