mirror of
https://github.com/501351981/vue-office.git
synced 2025-07-15 07:32:19 +08:00
Merge pull request #54 from lbw1998/replace-fetch
将excel读取文件的方法由fetch更改为xhr
This commit is contained in:
commit
f7caa3984d
@ -21,15 +21,25 @@ const themeColor = [
|
|||||||
let defaultColWidth = 80;
|
let defaultColWidth = 80;
|
||||||
const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
|
||||||
export function getData(src, options={}) {
|
export function getData(src, options={}) {
|
||||||
return fetchExcel(getUrl(src), options);
|
return requestExcel(getUrl(src), options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchExcel(src, options) {
|
function requestExcel(src, options) {
|
||||||
return fetch(src, options).then(res=>{
|
return new Promise(function(resolve, reject) {
|
||||||
if(res.status !== 200){
|
const xhr = new XMLHttpRequest();
|
||||||
return Promise.reject(res);
|
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);
|
||||||
}
|
}
|
||||||
return res.arrayBuffer();
|
};
|
||||||
|
xhr.onerror = function() {
|
||||||
|
reject(xhr.status);
|
||||||
|
};
|
||||||
|
xhr.send(options.body);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user