我正在使用谷歌 api 的 vue 2 和 Vue-gapi 包装器。我目前正在使用驱动器文件,我可以在验证我遇到的问题是使用我的方法列出来自谷歌驱动器的远程数据后上传文件。
这是方法
async listRemoteDrivesData() {
let files;
const formatFileSize = this.formatFileSize;
await window.gapi.load('client', function () {
window.gapi.client.load('drive', 'v3', function () {
gapi.client.drive.files.list({
"fields": "files(id,name,size,parents,createdTime)", // gets all metadata of the file
'q': 'fileExtension = "bak"' // gets the files with a .bak extension
}).then(function (response) {
files = response.result.files;
console.warn('files: ', files);
files.forEach((file) => {
file.size = formatFileSize(file.size);
file.path = '/Home Inventory Backup';
file.source = 'googleDrive'
})
}, function (err) {
console.log("Execute error", err);
});
})
})
console.warn('list of files: ', files);
this.listDriveFiles = files
},
我可以很好地获取文件列表。我的问题是将这些文件放入 listDriveFiles 属性中,以便我可以在我的数据表中使用该数据。它目前以未定义的形式出现。我需要一双新的眼睛来看看,看看我怎样才能让这个属性被填满。
过去两天我一直在分析这个问题,但无法弄清楚我哪里出错了?