1. 程式人生 > 其它 >vue-admin-template-master 功能實現

vue-admin-template-master 功能實現

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>