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

    .

  • 相关阅读:
    迷宫寻找路径数
    136. 只出现一次的数字
    48. 旋转图像
    283. 移动零
    面试题 01.06. 字符串压缩
    位运算符
    367. 有效的完全平方数
    868. 二进制间距
    SpringAOP表达式
    Mybatis常见错误及纠错
  • 原文地址:https://www.cnblogs.com/crazycode2/p/9607918.html
Copyright © 2011-2022 走看看