Vue项目 --- ajax插件axios

2018-07-11  本文已影响0人  V火力全开

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()
  }
上一篇 下一篇

猜你喜欢

热点阅读