mirror of
https://github.com/501351981/vue-office.git
synced 2025-07-25 07:41:42 +08:00
更改excel的fetch请求为xhr
This commit is contained in:
parent
b4e14063d9
commit
60767ec3b6
@ -21,16 +21,30 @@ const themeColor = [
|
||||
let defaultColWidth = 80;
|
||||
const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||
export function getData(src, options={}) {
|
||||
return fetchExcel(getUrl(src), options);
|
||||
return requestExcel(getUrl(src), options);
|
||||
}
|
||||
|
||||
function fetchExcel(src, options) {
|
||||
return fetch(src, options).then(res=>{
|
||||
if(res.status !== 200){
|
||||
return Promise.reject(res);
|
||||
}
|
||||
return res.arrayBuffer();
|
||||
});
|
||||
function request(src, options) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open(options.method || 'GET', src, true);
|
||||
xhr.responseType = options.responseType || 'arraybuffer';
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
resolve(xhr.response);
|
||||
} else {
|
||||
reject(xhr.status);
|
||||
}
|
||||
};
|
||||
xhr.onerror = function() {
|
||||
reject(xhr.status);
|
||||
};
|
||||
xhr.send(options.body);
|
||||
});
|
||||
}
|
||||
|
||||
function requestExcel(src, options) {
|
||||
return request(src, options);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user