vue项目中实现头像上传(axios请求)
2019-04-29 11:56
477 查看
vue项目中做个人资料时需要实现用户头像的更换
html部分
[code]<template> <div class="dataLeft"> <p class="pic" style="width: 106px"> <img :src="this.$picUrl+userInor.pic" alt="">//src部分是从后端获取的图像,再次不在赘述 </p> <p class="upload">上传头像 <input type="file" @change="upDataPic" enctype="" accept="image/*" class="uploadBtn"/> </p> </div> </template>
css部分
[code]<style> .pic{ width:106px; height:106px; overflow: hidden; border-radius:50%; background:white; } .pic img{ width: 100%; height: 100%; } .upload{ font-size:12px; text-align: center; line-height: 36px; } </style>
js部分
[code]<script> upDataPic(e){ let file = e.target.files[0]; var picData=new FormData(); picData.append('file',file,file.name); // console.log(picData) this.$http({ url:"接口url", method:'post', data:picData, }) .then(response=>{ if(response.data.success==true){ this.$swal.fire({//swal是引用的弹框插件,如需要,可百度查找 text:'上传成功', icon:'success' }) this.userIcon=response.data.filePath; this.getInfor(); }else{ this.$swal.fire({//swal是引用的弹框插件,如需要,可百度查找 text:res.data.msg }) } }) .catch(Error=>{ }) } </script>
相关文章推荐
- 详解Vue+axios+Node+express实现文件上传(用户头像上传)
- vue项目axios请求接口,后端代理请求接口404,问题出现在哪?
- 【vue+axios】一个项目学会前端实现登录拦截
- 【vue+axios】一个项目学会前端实现登录拦截
- vue结合axios实现restful风格的四种请求详解
- Vue项目首页_使用axios发送ajax请求
- vue2.0项目实战 使用axios发送请求
- vue.js使用axios实现跨域请求
- vue + qiniu(七牛) + axios 实现图片上传
- 【vue+axios】一个项目学会前端实现登录拦截
- vue项目之axios-header、请求拦截和响应拦截
- Vue项目之Axios数据请求
- Vue的axios插件实现GET、POST、JSONP请求,以及请求拦截
- vue+axios 开发环境与生产环境配置请求接口,本地开发和线上开发有多个请求地址怎么处理?上线后自动获取ip,不需改请求地址可运用多个项目中
- node+vue实现用户注册--头像上传
- Vue2.0 项目实战案例及Demo,基于vue2.0+vuex+vue-router+axios实现
- 基于vue-cli的vue项目之axios的使用3--get传参请求
- Vue项目中对axios进行封装以及api接口请求
- node+vue实现用户注册和头像上传的实例代码
- vue项目使用axios发送请求让ajax请求头部携带cookie的方法