let that = this;
wx.chooseMessageFile({
count: 1, //限制选择的文件数量
type: 'file',//非图片和视频的文件,不选默认为all
extension:['xls', 'xlsx'],//此处限制文件类型
// extension: ['xls', 'xlsx'], //此处限制文件类型
success(res) {
const tempFilePaths = res.tempFiles
console.log('临时路径', tempFilePaths)
//下面是返回后需要调接口的操作
// uni.uploadFile({
// url: 'https://******/index/Api/upload',
// filePath: tempFilePaths[0].path,
// name: 'file_',
// formData: {
// },
// success: (uploadFileRes) => {
// //接口返回的数据
// console.log(uploadFileRes.data);
// that.$token.toast("上传成功", 2000)
// that.file_name = uploadFileRes.data
// }
// });
}
})
上面是实现代码,调用后即可实现效果👇