axios安裝
npm install axios --save
引入
import axios from 'axios'
請求數(shù)據
axios.get(url)
.then(func)
url
是請求的接口地址,func
是對返回結果進行處理的回調函數(shù)
例子:
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()
}