1.使用axios
//安装
npm install --save axios
//组件内引入
import axios from 'axios'
//发送post请求(基于Pormise的)
axios.post("http://mp.yc.info",this.blog)
.then((res) => {
this.arr = res
console.log(res)
})
.then((res) => {})
2.全局配置
main.js文件中
import axios from 'axios'
Vue.prototype.$http = axios
axios.defaults.baseUrl = 'http://mp.yongchao.info'
axios.defaults.headers.common['Authorization'] = 'Token'
axios.defaults.headers.post['Content-type'] = 'application/urlencode'
axios.defaults.headers.get['Accepts'] = 'application/json'
axios.post("/getUser",this.blog)
.then((res) => {
this.arr = res
console.log(res)
})
网友评论