醋醋百科网

Good Luck To You!

在Vue中引入Axios并用来发起Ajax请求

一、安装

npm install axios


二、引入

在 Vue 工程的 main.js 中,引入 axios ,并绑定到 this.$http

async getStudentData() {
    const {
        data: res
    } = await this.$http.get(`http://www.linhongcun.club/student/getAllStudentByPage/${this.studentVO.page}/${this.studentVO.size}`);
    this.studentData = res.content;
    this.studentVO.total = res.totalElements;
    console.log(this.studentVO)
}


三、使用

在 .vue 文件的 method 中,编写方法,方法体里边,便可以通过 this.$http 发起 ajax 请求了!

async getStudentData() {
    const {
        data: res
    } = await this.$http.get(`http://www.linhongcun.club/student/getAllStudentByPage/${this.studentVO.page}/${this.studentVO.size}`);
    this.studentData = res.content;
    this.studentVO.total = res.totalElements;
    console.log(this.studentVO)
}
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言