1.安装fetch: npm install whatwg-fetch --save
2.在入口index.js文件中引入 import 'whatwg-fetch'
3.let url = global.commonIP + '/api/users/login'
let _this = this
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
loginName: 'yj',
password: 'yj',
})
}).then(function(res){
res.json().then(function(obj){
if(obj.errcode == '200'){
alert('登录成功')
_this.$router.push('/')
}
})
})
4.上传文件
let url = global.commonIP + 'api/uploadFile/upload'
let _this = this
let data = new FormData()
data.append('uploadFile', this.$refs.file.fil