试一下吧
[JavaScript] 纯文本查看 复制代码 <!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>TEST</title>
<!-- Vue 3 -->
<script src="https://candyissupersweet.gitee.io/cdn/vue3/vue.global.prod.js"></script>
</head>
<body>
<div id="app"> </div>
<script type="text/javascript">
let that = null, App = null;
App = {
mounted() {
that = this;
that.start();
},
methods: {
async start() {
await that.doSomeThing1();
await that.doSomeThing2();
await that.doSomeThing3();
},
doSomeThing1() {
console.log('第1件事');
},
doSomeThing2() {
return new Promise((res,rej)=>{
// 这里请求一些服务器的数据
const xhr = new XMLHttpRequest();
xhr.open('get', '/data.xlsx', true);
xhr.responseType = "arraybuffer";
xhr.onload = () => {
// 请求成功后返回
res(readXLSX(xhr.response))
};
xhr.send();
function readXLSX(data) {
console.log('第2件事');
that.byteLength = data.byteLength;
}
})
},
doSomeThing3() {
console.log('第3件事');
console.log(that.byteLength);
}
}
}
const app = Vue.createApp(App);
app.mount("#app");
</script>
</body>
</html> |