08.31 self-summary
Front and rear end interactive Vue-CLI project -axios
A. Mounting module
npm install axios --save
#--save可以不用写
II. Configuration main.js
import axios from 'axios'
Vue.prototype.$axios = axios;
III. Use
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);
})
}
Some submit different settings and ajax
- ajax in
tyle
heremethod
- The ajax
success
here isthem
not then back braces.
out catch
Please failure- Content is
$axios
before