多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
```js class Upload { constructor (parms) { this.url = parms.url } img (url) { const vm = this return new Promise((resolve, reject) => { wx.chooseImage({ success (res) { let tempFilePaths = res.tempFilePaths wx.uploadFile({ url: vm.url, filePath: tempFilePaths[0], name: 'imgFile', success (res) { if (res.statusCode === 200) { resolve(JSON.parse(res.data)) } else { console.log('上传失败') reject(res) } }, fail () { reject('上传失败到微信服务器失败') } }) } }) }) } } module.exports = new Upload({ url: 'http://uploadpic' }) ``` 调用: ```js const libs = require('../../libs/index') libs.upload.img().then(data => { console.log(data) }).catch(e => { console.log(e) }) ```