提交 c4b494ef 编写于 作者: D DCloud_LXH

fix(app): 修复createSelectorQuery.exec()在安卓低版本(如: 4.4.2)报错问题

上级 34841284
......@@ -5,7 +5,8 @@ import {
import getWindowOffset from 'uni-platform/helpers/get-window-offset'
import {
findElm
findElm,
elementMatchesPolyfill
} from './util'
function getRootInfo (fields) {
......@@ -95,7 +96,7 @@ function getNodeInfo (el, fields) {
}
function getNodesInfo (pageVm, component, selector, single, fields) {
const $el = findElm(component, pageVm)
const $el = elementMatchesPolyfill(findElm(component, pageVm))
if (!$el || ($el && $el.nodeType === 8)) { // Comment
return single ? null : []
}
......
......@@ -12,9 +12,9 @@ function findVmById (id, vm) {
}
}
export function findElm (component, pageVm) {
if (!pageVm) {
return console.error('page is not ready')
export function findElm (component, pageVm) {
if (!pageVm) {
return console.error('page is not ready')
}
if (!component) {
return pageVm.$el
......@@ -29,4 +29,22 @@ export function findElm (component, pageVm) {
}
}
return component.$el
}
}
export function elementMatchesPolyfill (Element) {
if (!Element.matches) {
Element.matches =
Element.matchesSelector ||
Element.mozMatchesSelector ||
Element.msMatchesSelector ||
Element.oMatchesSelector ||
Element.webkitMatchesSelector ||
function (s) {
var matches = (this.document || this.ownerDocument).querySelectorAll(s)
var i = matches.length
while (--i >= 0 && matches.item(i) !== this) {}
return i > -1
}
}
return Element
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册