我正在使用svelte+rollup+rollup-plugin-polyfill。
SCRIPT438: 对象不支持 "最接近 "属性或方法。
即使我加入了
polyfill(['@webcomponents/webcomponentsjs','element-closest']),
在我的rollup.js中。
调用发生在这段代码中。
function onDocumentClick (e) {
if (!e.target.closest('.autocomplete')) close();
}
为什么polyfill不存在呢,如何正确使用它?我想用IE11支持的.closeest替换掉。
使用Polyfill([@webcomponentswebcomponentsjs],'...
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector ||
Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
Element.prototype.closest = function(s) {
var el = this;
do {
if (Element.prototype.matches.call(el, s)) return el;
el = el.parentElement || el.parentNode;
} while (el !== null && el.nodeType === 1);
return null;
};
}