Vueの-CLIフロントとリアエンドモジュールインタラクティブプロジェクト-axios(似たAJAXの提出)

08.31自己概要

フロントとリアエンドインタラクティブヴュー-CLIプロジェクト-axios

A.モジュール実装

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

II。設定main.js

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

III。使用

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こちらmethod
  • アヤックスsuccessここでは、them当時ではないブレース.アウト
  • catchしてください失敗
  • コンテンツがある$axios前に

おすすめ

転載: www.cnblogs.com/pythonywy/p/11440622.html