首页 > 移动平台 > 详细

AXIOS 的请求

时间:2018-12-05 01:47:24      阅读:201      评论:0      收藏:0      [点我收藏+]

AXIOS 本质上等同于json 传值

1.引用

技术分享图片
1 //引入axios
2 import Axios from ‘axios‘
3 //将axios挂载到 Vue原型上
4 Vue.prototype.$https = Axios
5 
6 //设置公共的url
7 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:0
15                         }
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))

最终赋值的方式获取结果

 

AXIOS 的请求

原文:https://www.cnblogs.com/zhangqing979797/p/10068232.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!