1.安装axios

cnpm i axios -S

2.方案一:修改原型链

首先,在main.js中引入

vue使用axios上传文件

在这个时候,你还是无法在组件中使用axios的,但如果将vue改为vue的原型链,就可以解决这个问题,如下图

vue使用axios上传文件

开始发送请求

//获取表单中的file	
var file_obj = document.getElementById('fileaaa').files[0];
		alert(file_obj)
		console.log(file_obj);
		let formdata = new FormData()
		formdata.append('file', file_obj)
		formdata.append('title', "sadasdsa")
		formdata.append('url', "urlsadsasaassad")

		this.$ajax.post('/index/addBanner', formdata, {
		    headers: {
			    "Content-Type": "multipart/form-data"
				         }
					})
					.then(function(response) {
						console.log(response);
					})

			},

成功

相关文章:

  • 2022-12-23
  • 2022-01-06
  • 2022-01-23
  • 2021-06-05
  • 2022-12-23
  • 2021-10-31
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
相关资源
相似解决方案