1 <input v-on:change="change" multiple id="file" class="addpic" type="file" style="width: 113px;height: 59px;opacity: 0;"> 2 <div id="box"></div>
const uploadImg= function () { var formdata = new FormData(); formdata.append("pic", $('.addpic')[0].files[0]); $.ajax({ url: '', type: 'POST', data: formdata, dataType: 'JSON', cache: false, processData: false, contentType: false }).done(function (ret) { if (ret.status != 0) { alert("上传文件格式不合法!请选择(jpg,jpeg,gif,bmp,png)格式的图片"); return; } console.log(ret.data.url); }); };
Solve problems in the most elegant way