1、添加路由
{ path: '/teacherTest', component: Layout, redirect: '/teacherTest/table', name: '講師管理測試', meta: { title: '講師管理測試', icon: 'example' }, children: [ { path: 'tableTest', name: '講師列表測試', component: () => import('@/views/edu/teacherTest/list'), meta: { title: '講師列表測試', icon: 'table' } }, { path: 'savetTest', name: '添加講師測試', component: () => import('@/views/edu/teacherTest/save'), meta: { title: '添加講師測試', icon: 'tree' } } ] },
2、創建路由對應頁面 list.vue 、save.vue
3、創建teacher.js定義訪問接口地址
import request from '@/utils/request' export default { //1講師列表(條件查詢分頁) //current 當前頁 limit每頁記錄數 teacherQuery條件對象 getTeacherListPage(current,limit,teacherQuery){ return request({ url:`/eduservice/teacher/pageTeacherCondition/${current}/${limit}`, method:'post', //teahcerQuery條件對象,后端使用RequestBody獲取數據 //data表示把對象轉換為json進行傳遞到接口里面 data:teacherQuery }) } }
4、在講師列表頁面調用定義的接口方法,得到接口返回數據
<template> <div class="app-container">講師列表 <el-table v-loading="listLoading" :data="list" element-loading-text="數據加載中" border fit highlight-current-row> <el-table-column label="序號" width="70" align="center"> <template slot-scope="scope"> {{ (page - 1) * limit + scope.$index + 1 }} </template> </el-table-column> <el-table-column prop="name" label="名稱" width="80" /> <el-table-column label="頭銜" width="80"> <template slot-scope="scope"> {{ scope.row.level===1?'高級講師':'首席講師' }} </template> </el-table-column> <el-table-column prop="intro" label="資歷" /> <el-table-column prop="gmtCreate" label="添加時間" width="160"/> <el-table-column prop="sort" label="排序" width="60" /> <el-table-column label="操作" width="200" align="center"> <template slot-scope="scope"> <router-link :to="'/edu/teacher/edit/'+scope.row.id"> <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button> </router-link> <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">刪除</el-button> </template> </el-table-column> </el-table> </div> </template> <script> //引入調用teacher.js文件 import teacher from "@/api/teacher/teacher"; export default { data() { //定義變量和初始值 return { list: null, //查詢之后接口返回的集合 page: 1, //當前頁 limit: 10, //每頁記錄數 total: 0, //總記錄數 teacherQuery: { //條件封裝對象 }, }; }, created() { //頁面渲染之前執行,一般調用methods定義的方法 this.getList(); }, methods: { //創建具體的方法,調用teacher.js定義的方法 getList() { teacher .getTeacherListPage(this.page, this.limit, this.teacherQuery) .then((response) => { //請求成功 //response接口返回的數據 this.list = response.data.rows; this.total = response.data.total; }) .catch((error) => { console.log(console.error()); }); }, }, }; </script>