iview在IE报TypeError: 无法获取未定义或 null 引用的属性transfer

iview在IE9下面报如下错误:

[Vue warn]: Error in directive transfer-dom inserted hook: “TypeError: 无法获取未定义或 null 引用的属性“transfer””.

其原因是IE9不支持dataset属性导致的,所以需要在全局定义dataset属性

// 修复IE10及以下版本不支持dataset属性的问题,兼容transfer-dom.js中使用了dataset的问题
if (isIE() && window.HTMLElement) {
if (Object.getOwnPropertyNames(HTMLElement.prototype).indexOf('dataset') === -1) {
Object.defineProperty(HTMLElement.prototype, 'dataset', {
get: function() {
let attributes = this.attributes;
let name = [],
value = [];
let obj = {};
for (let i = 0; i < attributes.length; i++) {
if (attributes[i].nodeName.slice(0, 5) == 'data-') {
name.push(attributes[i].nodeName.slice(5));
value.push(attributes[i].nodeValue);
}
}
for (let j = 0; j < name.length; j++) {
obj[name[j]] = value[j];
}
return obj;
}
});
}
}

转载于:https://blog.csdn.net/qq_19739063/article/details/79635724

猜你喜欢

转载自blog.csdn.net/a460550542/article/details/81122147