使用axios请求数据过程
1. 导入axios包
import axios from 'axios'
2. 在钩子函数中调用函数
mounted() {this.getinitialdata() //获取初始页面数据},
3. 在methods中声明函数
tips:
①以对象形式指定需要从接口中获取的数据
②使用axois请求数据:
post(“后端所给的数据接口名称”,需要传递的参数)
getinitialdata() {//获取初始化数据let data = {// 需要传递的参数page: this.formInline.pageCode,limit: this.formInline.pageSize,state: 4, };this.axios.post("goods/goods_order", data).then((resp) => {this.tableData = resp.data.data; // 界面需要的数据,赋值指定的数据this.totalLength = resp.data.count;});}
添加界面需要的数据字段名称
以elementUI的表格为例,prop中即后端所给定的字段名称:
<el-table-column prop="count" label="数量" />