AXIOS 的请求

AXIOS 本质上等同于json 传值

1.引用

技术分享图片
技术分享图片

1 //引入axios2 import Axios from ‘axios‘3 //将axios挂载到 Vue原型上4 Vue.prototype.$https = Axios5 6 //设置公共的url7 Axios.defaults.baseURL = ‘https://www.luffycity.com/api/v1/‘;

引用

2.使用

技术分享图片
技术分享图片

 1  //获取 分类列表的数据 2  getCategoryList(){ 3  this.$https.get(‘course_sub/category/list/‘) 4  .then((res)=>{ 5  console.log(res); 6  var data = res.data; 7  8  if(data.error_no === 0){ 9 10  this.categoryList = data.data;11  let obj = {12  id:0,13  name:‘全部‘,14  category:015  }16  this.categoryList.unshift(obj);17  // 数组 删除任意一个指定的元素18  //指定数组中的索引 删除指定的元素 数组.splice(起始位置,删除的个数)19  }20  })21  .catch((err)=>{22  console.log(‘获取列表失败‘,err)23  })24 },

需要在后面created()调用

3.

本质上,通过挂载的方式进行全局的使用

挂载.get()

,then(function(response))

.catch(function(response))

最终赋值的方式获取结果

 

相关文章