zoukankan      html  css  js  c++  java
  • axios 和 vue-axios

    1.main.js 全局引入

    /**
     * 引入 axios 数据请求方式
     * axios 和 VueAxios 必须同时注入
     */
    import axios from 'axios'
    import VueAxios from 'vue-axios'
    Vue.use(VueAxios, axios)

    2.代理 proxyTable

    完整接口

    https://h5.manhua.163.com/category/1004.json?page=1

    设置代理 config/index.js

    // 设置代理,解决跨域问题
    proxyTable: {
      '/api': {
        target: 'https://h5.manhua.163.com/', // 接口的域名
        secure: false,  // 如果是https接口,需要配置这个参数
        changeOrigin: true, // 如果接口跨域,需要进行这个参数配置
        pathRewrite: {
          '^/api': ''
        }
      }
    },

    3.页面调用

    get 方式

    this.axios.get('category/1004.json',{
      params:{
        page: 1
      }
    }).then((response) => {
      console.log(response.data.data.books);
    }).catch((err) => {
      //
    })

    post 方式

    this.axios.post('category/1004.json',{
      page: 1
    },{
      headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).then((response) => {
      console.log(response);
    }).catch((err) => {
      console.log(err);
    })

    .

  • 相关阅读:
    83. Remove Duplicates from Sorted List
    141. Linked List Cycle
    hdu1028 划分数
    XDU1019 阶乘因子的个数
    poj2773 容斥原理
    poj1091 容斥原理的应用
    poj1173 多重集组合数
    HDU 1465 错排问题
    poj 1496
    复习之求一个数的约束之积模一个质数
  • 原文地址:https://www.cnblogs.com/crazycode2/p/9607918.html
Copyright © 2011-2022 走看看