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
前に