图片.png一、前端实现

1、组件模板

  1. <!-- 课程讲师 -->
  2. <el-form-item label="课程讲师">
  3. <el-select
  4. v-model="courseInfo.teacherId"
  5. placeholder="请选择">
  6. <el-option
  7. v-for="teacher in teacherList"
  8. :key="teacher.id"
  9. :label="teacher.name"
  10. :value="teacher.id"/>
  11. </el-select>
  12. </el-form-item>

2、定义api

api/edu/teacher.js

  1. getList() {
  2. return request({
  3. url: api_name,
  4. method: 'get'
  5. })
  6. },

组件中引入teacher api

  1. import teacher from '@/api/edu/teacher'

3、组件脚本

定义data

  1. teacherList: [] // 讲师列表

表单初始化时获取讲师列表

  1. init() {
  2. ......
  3. // 获取讲师列表
  4. this.initTeacherList()
  5. },
  6. initTeacherList() {
  7. teacher.getList().then(response => {
  8. this.teacherList = response.data.items
  9. })
  10. },