element ui组件方法的传递 //引入 组件。 <el-upload class="avatar-uploader" :action="action" :http-request="uploadFile" :show-file-list="false"> <img v-if="imageUrl" :src="imageUrl" class="avatar"> <i v-else class="el-icon-plus avatar-uploader-icon"></i> </el-upload> uploadFile(data){ var userinfo = this.$baseMethod.getStore('_ccmUser') let formdata = new FormData(); formdata.append('file',data.file); formdata.append('token',userinfo.token); formdata.append('op',"uploadChannelPic"); formdata.append('data',JSON.stringify({})); uploadFile(formdata).then(res => { this.imageUrl = JSON.parse(res.data).picUrl // console.log(JSON.parse(res.data)) }) },
这一段是js上传FormData请求格式
<input type="file" id="file" //设置上传格式化 accept="image/jpg,image/jpeg,image/png,image/gif" //获取上传内容 @change="fileUpload()" /> fileUpload() { var f = document.getElementById('file').files[0]; let formdata = new FormData() formdata.append('file',f); formdata.append('token',storage.get('loginToken')); formdata.append('op',"uploadChannelPic"); formdata.append('data',JSON.stringify({})); //这里是请求接口进行传递formdata this.$upload("/channel/perfection/uploadFile",formdata ).then(res => {
//请求成功后赋值给要展示的图片 this.fileImg = JSON.parse(res.data).picUrl }) },