由于业务要求上传证书的功能,即上传图片,做一下笔记;
tool是我自己封装的微信小程序接口,具体实现看微信小程序或Taro官方文档;req开头的函数也是我自己封装的网络请求;不能够直接复制运行。
界面需要三个东西 上传图片的按钮,选择的按钮,以及上传图片后的图片展示。
//选择图片的按钮
//图片展示
//确认上传图片的按钮
确认上传证书
选择图片函数chooseImage
chooseImage = () => {
Taro.chooseImage({
count: 1,
sizeType: ['original','compressed'],
sourceType: ['album','camera'],
success: (res) => {
tool.showInfo('正在上传...','loading')
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
let tempFilePaths = res.tempFilePaths;
this.setState({
tempFilePaths: tempFilePaths[0],
},()=>{
console.log(tempFilePaths);
})
}
})
}
上传图片函数uploa