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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM