标签:请求方式 失败 install 组件 npm ram main out ||
npm install axios --save
#--save可以不用写
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提交不同的一些设置
tyle这里是methodsuccess这里是them且不在大括号内后面接着.出来catch请失败$axios之前Vue-CLI项目-axios模块前后端交互(类似ajax提交)
标签:请求方式 失败 install 组件 npm ram main out ||
原文地址:https://www.cnblogs.com/pythonywy/p/11440622.html