axios安装
npm install axios --save
引入
import axios from 'axios'
请求数据
axios.get(url)
.then(func)
url
是请求的接口地址,func
是对返回结果进行处理的回调函数
例子:
methods: {
getHomeInfo () {
axios.get('/api/index.json?city=' + this.city)
.then(this.getHomeInfoSucc)
},
getHomeInfoSucc (res) {
res = res.data
if (res.ret && res.data) {
const data = res.data
this.swiperList = data.swiperList
}
}
},
mounted () {
this.getHomeInfo()
}