vue & axios

1:npm install axios

2:在main.js引入

import axios from 'axios'
Vue.prototype.axios = axios

3:
post/get/put
this.axios.post('url', {firstName: this.Fred, lastName: this.Flintstone,}).then(function (response) {
    console.log(response);
  }).catch(function (error) {
    console.log(error);
  });
参数后加token 
{imagedata: vm.urls, token: token}



post form
login () {
console.log(1)
let vm = this
this.$http.post('http://39.106.96.131:9392/login?userno=' + vm.user + '&password=' + vm.password).then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
}

post formdata 提交
this.$http.post(this.base + '/login', 'userno=' + vm.user + '&password=' + vm.password, {headers: {
'Content-Type': 'application/x-www-form-urlencoded'}}).then(res => {
console.log(res)
}).catch(err => {
console.log(err)
})
}
 
 
posted @ 2019-07-25 09:40  sosolucky  阅读(131)  评论(0编辑  收藏  举报