zoukankan      html  css  js  c++  java
  • 【1118 | Day61】Vue-CLI项目功能插件之Vue-axios

    一.模块的安装

    npm install axios --save
    #--save可以不用写
    

    二.配置main.js

    import axios from 'axios'
    Vue.prototype.$axios = axios;
    

    三.使用

    created() {  // 组件创建成功的钩子函数
        // 拿到要访问课程详情的课程id
        let id = this.$route.params.pk || this.$route.query.pk || 1;
        this.$axios({
            url: `http://127.0.0.1:8000/course/detail/${id}/`,  // 后台接口
            method: 'get',  // 请求方式
        }).then(response => {  // 请求成功
            console.log('请求成功');
            console.log(response.data);
            this.course_ctx = response.data;  // 将后台数据赋值给前台变量完成页面渲染
        }).catch(error => {  // 请求失败
            console.log('请求失败');
            console.log(error);
        })
    }
    

    与ajax提交不同的一些设置

    • ajax 中的tyle这里是method
    • ajax中的success这里是then且不在大括号内后面接着.出来
    • catch请失败
    • axios可能会用到的参数responseType:'blob'这是让请求的内容返回二进制
  • 相关阅读:
    在 Spring 中使用 Quartz
    Quartz 快速进阶
    任务调度概述
    Spring Boot 2.x 整合 Mybatis 3.x
    pwd函数实现
    07-图4 哈利·波特的考试 (25 分)
    06-图3 六度空间 (30 分)
    linux中的目录
    Linux中的文件
    06-图2 Saving James Bond
  • 原文地址:https://www.cnblogs.com/fxyadela/p/11885914.html
Copyright © 2011-2022 走看看