CRMEB PC 上传图片方法
上传地址:
/web/auth_api/upload
post
------WebKitFormBoundaryI4OkcF67NzjB2NQn Content-Disposition: form-data; name="file"; filename="黑喵.png" Content-Type: image/png ------WebKitFormBoundaryI4OkcF67NzjB2NQn--
模板:
<input ref="upimg" @change="photoChange" class="finput" type="file" accept="image/*">
methods:
photoChange(el) { var file = el.target.files[0];//name: "dangqi1.png" || type: "image/png" var type = file.type.split('/')[0]; if ( type === 'image' ){ this.upload(file); }else{ alert('上传了非图片'); } }, upload(file) { let formData = new FormData(); formData.append('file', file); expertApi.upFile(formData).then(function(res){ console.log('res',res); }); },
expertApi.js
define([ 'scripts/http' ], function (request) { return { /** * 上传 * ****/ upFile: function(data){ return request({ url: '/auth_api/upload', method: 'post', headers: { 'Content-Type': 'multipart/form-data',//设置请求头请求格式为JSON }, data: data }); } }; });