data()当我处于 时,我无法访问我的任何数据onUploadProgress。每次都会返回“未定义”。<template> <el-upload ref="upload"></el-upload> <el-button type="primary" :loading="isOnUploading" @click="submitUpload">{{ $t('add') }}</el-button></template>export default { data() { return { isOnUploading: false, }},methods: { async uploadFile(event) { const data = new FormData(); data.append('file', event.file); await this.$axios.post(this.uploadUrl, data, { onUploadProgress: function (progressEvent) { console.log(this.isOnUploading); // Return undefined } }); } submitUpload() { this.$refs.upload.submit(); }}当我调用一个方法时,它给了我同样的问题,它告诉我它是未知的。为什么 ?
1 回答
慕桂英546537
TA贡献1848条经验 获得超10个赞
绑定你的 vue 实例:
await this.$axios.post(this.uploadUrl, data, {
onUploadProgress: function (progressEvent) {
console.log(this.isOnUploading);
}.bind(this)
});
添加回答
举报
0/150
提交
取消