uni-app VUE3调用uni.getSavedFileList is not a function

uni-app VUE3调用uni.getSavedFileList is not a function

开发环境 版本号 项目创建方式
Mac 12.0.1 HBuilderX
### 操作步骤:
```javascript
uni.getSavedFileList({  
    success: function (res) {  
        console.log(res.fileList)  
    }  
})

预期结果:

uni.getSavedFileList({  
    success: function (res) {  
        console.log(res.fileList)  
    }  
})

实际结果:

使用hello-uniapp标准运行基座直接测试

uni.getSavedFileList({  
    success: function (res) {  
        console.log(res.fileList)  
    }  
})

bug描述:

使用hello-uniapp标准运行基座直接测试

uni.getSavedFileList({  
    success: function (res) {  
        console.log(res.fileList)  
    }  
})

更多关于uni-app VUE3调用uni.getSavedFileList is not a function的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

HBuilder X 3.4.4-alpha已修复,请升级

更多关于uni-app VUE3调用uni.getSavedFileList is not a function的实战教程也可以访问 https://www.itying.com/category-93-b0.html


V3确实存在,V2没有问题

bug 已确认 ,预计下个版本更新修复

用plus.io搞定了

uni-app 中使用 Vue3 时,如果你遇到 uni.getSavedFileList is not a function 的错误,可能是因为以下原因之一:

1. 检查 uni-app 的版本

uni.getSavedFileListuni-app 提供的 API,确保你使用的 uni-app 版本支持该 API。如果版本过低,可能会导致该 API 不可用。

你可以通过以下命令检查 uni-app 的版本:

npm list [@dcloudio](/user/dcloudio)/uni-app

如果需要更新 uni-app,可以使用以下命令:

npm install [@dcloudio](/user/dcloudio)/uni-app[@latest](/user/latest)

2. 检查运行环境

uni.getSavedFileList 是一个小程序特有的 API,确保你在小程序环境下调用该 API。如果你在 H5 或 App 环境下调用,可能会导致该 API 不可用。

你可以通过以下代码判断当前运行环境:

if (uni.getSystemInfoSync().platform === 'devtools') {
  console.log('当前运行在小程序开发者工具中');
} else if (uni.getSystemInfoSync().platform === 'ios' || uni.getSystemInfoSync().platform === 'android') {
  console.log('当前运行在 App 环境中');
} else {
  console.log('当前运行在 H5 环境中');
}

3. 检查 API 调用方式

确保你正确调用了 uni.getSavedFileList 方法。以下是一个正确的调用示例:

uni.getSavedFileList({
  success(res) {
    console.log('已保存的文件列表:', res.fileList);
  },
  fail(err) {
    console.error('获取文件列表失败:', err);
  }
});

4. 检查 Vue3 的 setup 语法

如果你在 Vue3 的 setup 中使用 uni.getSavedFileList,确保你正确地导入了 uni 对象。以下是一个示例:

import { onMounted } from 'vue';

export default {
  setup() {
    onMounted(() => {
      uni.getSavedFileList({
        success(res) {
          console.log('已保存的文件列表:', res.fileList);
        },
        fail(err) {
          console.error('获取文件列表失败:', err);
        }
      });
    });
  }
};
回到顶部