zoukankan      html  css  js  c++  java
  • AXIOS 的请求

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

    最终赋值的方式获取结果

  • 相关阅读:
    WordPress在nginx服务器伪静态
    excel根据一列的值匹配另一列
    linux上安装Anaconda并创建python虚拟环境
    python模块学习之numpy
    大数据测试工具
    python学习路线
    spark event log
    夏令时
    spark学习指南
    Yarn和Spark对比
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/10068232.html
Copyright © 2011-2022 走看看