美文网首页
Vue项目 --- ajax插件axios

Vue项目 --- ajax插件axios

作者: V火力全开 | 来源:发表于2018-07-11 22:05 被阅读0次

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()
  }

相关文章

网友评论

      本文标题:Vue项目 --- ajax插件axios

      本文链接:https://www.haomeiwen.com/subject/fjpkpftx.html