<el-upload
:action="https://up-z2.qiniup.com"
:data="postData"
:before-upload="beforeUpload"
list-type="picture-card">
<i class="el-icon-plus" />
</el-upload>
import { getToken } from "@/api/qiniu"
data() {
return {
postData: { key: "", token: "" }
}
},
methods:{
beforeUpload(file) {
getToken().then(response => {
const token = response
this.postData = {
key: file.name,
token: token
}
})
}
}
qiniu.js
import request from "@/utils/request"
export function getToken() {
return request({
url: "/base/qtoken",
method: "get"
})
}
I would like to ask, isn"t before-upload executed before uploading? Why do I always visit https://up-z2.qiniup.com and then access the token interface every time I upload? if token doesn"t get it, it causes an error report
.
Uncaught (in promise) error
Uncaught (in promise) error