IE 11 会触发Object doesn't support property or method 'includes'
,因为它在 IE11 中不受支持:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes#Browser_compatibility
您必须添加以下填充物才能正常工作:
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}
if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
};
}
我已将其添加到我的index.jsx
中,它解决了除一个之外的任何.includes()
出现的问题,我不确定为什么。
我在 React 容器中有这段 JS:
removeInfectedFiles() {
let { filesAccepted } = this.state;
const { infected } = this.props.upload.data;
this.setState({
...this.state,
filesAccepted: filesAccepted.filter(
file => !infected.includes(file.key)
)
})
var filesInfected = [];
_.map(infected, i => {
filesInfected.unshift(
<p key={ i }>{ i }</p>
)
});
this.setState({
filesInfected
})
}
适用于除IE 11以外的所有其他浏览器。
在将文件写入服务器之前,会对其进行病毒扫描。如果文件有,服务器会响应被感染的文件列表,应该是"this.props.upload.data...并且显然不会将它们写入服务器。这会从已成功提交的文件列表中删除文件名。
Array.prototype.includes()
与String.prototype.includes()
不同。如果数组是数组,则需要为数组方法包含 pollyfillinfected
。