k***@163.com
k***@163.com
  • 发布:2025-02-09 15:21
  • 更新:2025-02-09 21:45
  • 阅读:29

this.$el.querySelector is not a function

分类:uni-app
mounted() {  
            console.log( typeof (this.$el) );  
            console.log(this.$el.querySelector(".xxx"))  

            console.log( this.$el.ownerDocument )  
            if( this.$el.ownerDocument ){  
                let a = this.$el.ownerDocument.querySelector(".xxx")  
                console.log(a);  
            }else console.log(null)  
        },

第二步就报错了
15:15:05.341 object at pages/setting/ble_search.vue:313
15:15:05.344 [Vue warn]: Error in mounted hook: "TypeError: this.$el.querySelector is not a function"

开始的$el有说是html元素,但输出是object
后面的 this.$el.ownerDocument 是有值的
this.$el.ownerDocument.querySelector还是会报不是一个函数

2025-02-09 15:21 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com

querySelector /querySelectorAll只是浏览器环境的api,也就是网页端才能用,小程序端和app端获取元素和节点需要用专有的方法,你去看下官网关于节点和element相关的文档吧。

要回复问题请先登录注册