Vue+axios 获取 后端 数据 并 展示
发布时间
阅读量:
阅读量
在Vue框架中,通过引入axios客户端来完成对后台数据的调用及前端展示工作。
首先需要进行axios的安装操作:
采用npm工具进行安装:
npm install axios
查阅项目中的package.json文件,如在“dependencies”字段中检测到axios的存在,则说明安装过程已顺利完成

在使用axios之前,必须确保已完成相应的引入操作!
import axios from 'axios'
在获取后端数据时,可以采用axios库所提供的get方法进行操作:
axios.get('api').then(res=>{
//alert("111");
this.College = res.data.College;
//将api中College数据读入到此文件中的College数据中
})
.catch(erroe=>{
alert("error");
})
全部评论 (0)
还没有任何评论哟~
