当我从其他 View 使用 ionic 时,我在控制台上收到此错误 Uncaught TypeError: Cannot read property 'querySelectorAll' of undefined ionic.bundle.js:2800,但我不知道这是什么意思,以及如何解决它
最佳答案
免责声明:我对 ionic 没有太多经验,这是基于我对一般 JavaScript 的经验。
您的错误可能来自于代码所依赖的特定元素,当您切换 View 时找不到该元素。我从 querySelectorAll
收集到这个作为元素的属性。它用于通过提供的 CSS Selector 获取子元素.它经常用作 document.querySelectorAll
以获取页面上与查询匹配的任何元素。
根据您提供给我们的信息,每次 View 更改时,您的代码(或内部库)似乎都在尝试对特定 View 中的元素使用 querySelectorAll
,无论是否它是包含或不包含元素的 View 。这不可避免地导致特定元素为 undefined
,因此没有 querySelectorAll
属性。这是一些模拟代码,它们会导致与您遇到的问题大致相同的问题。
# This would be run every time the view changes.
let myElement = document.querySelectorAll('#element-in-different-view');
myElement === undefined; // true
myElement.querySelectorAll('#foo');
// undefined is not an Element, and as such doesn't have the property `querySelectorAll`
Important Note: As a community, we can provide you with more specific answers if you include the full traceback you get and a mvce.
关于javascript - 无法读取未定义的属性 'querySelectorAll',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52583100/