课程程大纲-章节修改(前端)

1、添加修改章节方法

在course/chapter.vue页面的编辑按钮中添加修改章节方法。

java 复制代码
<el-button style type="text" @click="openUpdateChapter(chapter.id)">编辑</el-button>

2、方法调用接口实现章节的数据回显

(1)实现章节的数据回显的方法JS 实现

java 复制代码
//根据章节id查询章节的回显数据
    openUpdateChapter(chapterId) {
      //显示弹框
      this.dialogChapterFormVisible = true;
      //调用接口回显数据
      chapter.getChapterInfo(chapterId).then(response => {
        this.chapter = response.data.chapter;
      });
    },

(2)修改章节数据方法JS实现

java 复制代码
//新增获取修改章节
    saveOrUpdate() {
      if (this.chapter.id) {
        //修改
        this.updateChapterInfo()
      } else {
        //添加
        this.saveChapter();
      }
    },
    //修改章节
    updateChapterInfo() {
      //调用接口实现
      chapter.updateChapter(this.chapter).then(response => {
        //关闭修改弹框
        this.dialogChapterFormVisible = false;
        //提示
        this.$message({
          type: "success",
          message: "修改章节成功!"
        });
        //刷新页面
        this.getChapterVideoList();
      });
    },

3、修改后,再点击添加

(1)出现问题:刚刚修改的章节数据未被清空。

(2)解决方案:添加章节方法中添加清空数据的方法。

java 复制代码
<el-button type="text" @click="openAddChapter()">添加章节</el-button>
. . . . . .
//添加章节前的操作
    openAddChapter(){
       //显示弹框
      this.dialogChapterFormVisible = true
      //清空数据
      this.chapter={}
    },
相关推荐
s***117020 小时前
Spring+Quartz实现定时任务的配置方法
java
j***630820 小时前
Spring Boot 多数据源解决方案:dynamic-datasource-spring-boot-starter 的奥秘(上)
java·spring boot·后端
z***677720 小时前
Spring Boot 实战:轻松实现文件上传与下载功能
java·数据库·spring boot
q***017720 小时前
Java进阶学习之路
java·开发语言·学习
4***g89420 小时前
Spring Boot Admin 踩坑
java·spring boot·后端
s***353020 小时前
将 vue3 项目打包后部署在 springboot 项目运行
java·spring boot·后端
一辉ComeOn20 小时前
[源码系列:手写Spring] AOP第二节:JDK动态代理 - 当AOP遇见动态代理的浪漫邂逅
java·后端·spring
Zx6236520 小时前
13.泛型编程 STL技术
java·开发语言·c++
b***653220 小时前
SpringBoot的@Scheduled和@Schedules有什么区别
java·spring boot·spring
w***48121 小时前
CVE-2024-38819:Spring 框架路径遍历 PoC 漏洞复现
java·后端·spring