# uni练手 **Repository Path**: wx_8f09a3c8d9/uni-practice ## Basic Information - **Project Name**: uni练手 - **Description**: 第一个uni练手项目 只打了安卓包 用了之后对uni印象很差,文档东一脚西一脚还很乱,不建议入坑 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-02 - **Last Updated**: 2021-07-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 灵工优享 ## 箱规管理 登录、个人中心、箱规采集、箱规图片上传、箱规信息提交 ## 图片上传插件 components => sunui-upimg => sunui-upimg.vue **文件名修改** file_name: { type: String, default: 'file' }, **主要代码** const uploadTask = uni.uploadFile({ url: url, filePath: path, name: 'file', formData: { 'name': name }, success: function(res) { var data = res.data; console.warn('sunui-upimg - 如发现没有获取到返回值请到源码191行修改后端返回图片路径以便正常使用插件', JSON.parse(data)); try { //Tip : 切记->主要修改这里图片的返回值为真实返回路径!!! 详情见示例 data = JSON.parse(res.data).result; } catch (e) { throw (e, data); } // 根据自己的返回数据做相应判断,服务器返回200即代表成功请求 if (res.statusCode == 200) { if (success) { success(data); } } else { if (fail) { fail(data); } } }, fail: function(res) { console.log(res); if (fail) { fail(res); } } }); ## uniapp请求封装 api.js MinRequest.js **在main.js添加** import MinRequest from './MinRequest' import minRequest from './api' Vue.use(MinRequest) const app = new Vue({ ...App, minRequest }) **在page页面调用** methods: { // 使用方法一 testRequest1 () { this.$minApi.uniapp({wd: 'uni-app'}).then(res => { this.res = res console.log(res) }).catch(err => { console.log(err) }) }, // 使用方式二 async testRequest2 () { try { const res = await this.$minApi.uniapp({wd: 'uni-app'}) console.log(res) } catch (err) { console.log(err) } } } ## 素材 基于 ColorUI