记一次新增的过程

index.vue文件

在这里插入图片描述

逻辑:拿一个数据对象push到数组中(前端逻辑)
实际:把数据对象传给后端即可,列表是由前端请求后端数据进行展示
分析:数据对象从哪里来?-- 页面用户输入
步骤:编写前端页面,在页面点击提交按钮,发送后端post请求

1.找到新增按钮身上的方法
在这里插入图片描述

 // 导入按钮
  importBtn() {
      this.$nextTick(() => {
          this.$refs.addTool.dialogTableVisible = true // 显示组件
          this.$refs.addTool.isDisabled = false
          this.keyWord = '';
          this.isroleAdd = true;
      })
  },

2.可以看出添加页面是一个组件,点击按钮时显示这个组件;编辑页面同理

 // 导入按钮
  importBtn() {
      this.$nextTick(() => {
          this.$refs.addTool.dialogTableVisible = true // 显示组件
          this.$refs.addTool.getdata(id);
      })
  },

3.编写页面组件,发送请求

  • 表单项如下:

在这里插入图片描述

  • 提交按钮

在这里插入图片描述

btnOK() {
this.$refs.deptForm.validate(val => {
  if(val) {
    var params = {
      technologyName: this.formData.technologyName,
      technologyInfo: this.formData.technologyInfo,
      content: this.formData.content,

      fileName: this.formData.fileName, //文件上传
      fileUrl: this.formData.fileUrl,

      iconUrl: JSON.stringify(this.arrImg),
    }
    if(!this.formData.id) {
      // add
      this.http
      .post(this.api.advancedTechnology.post_addAdvancedTechnology, params)
      .then(res => {
          if (res.code == 200) {
              this.$message({
                  message: res.message,
                  type: 'success'
              });
              this.$parent.getDocumentList();
              this.dialogTableVisible = false
              this.isroleAdd = false;
          }else if(res.code == 201){
              this.$message({
                  message: res.message,
                  type: 'warning'
              });
          }else {
              this.$message({
                  message: res.message,
                  type: 'error'
              });
          }
      })
    } else {
      // edit
      this.http
      .put(this.api.advancedTechnology.put_editAdvancedTechnology,
      {...params, 
      id: this.formData.id, 
      creator: this.formData.creator, 
      fileUrl: this.zhongjianliang == this.fileObject.url ? this.zhongjianliang : this.fileObject.url
      })
      .then(res => {
          if (res.code == 200) {
              this.$message({
                  message: res.message,
                  type: 'success'
              });
              this.$parent.getDocumentList();
              this.dialogTableVisible = false
              this.isroleAdd = false;
          }else if(res.code == 201){
              this.$message({
                  message: res.message,
                  type: 'warning'
              });
          }else {
              this.$message({
                  message: res.message,
                  type: 'error'
              });
          }
      })
    }
    
  }
})
}

添加成功,提示操作成功,刷新列表

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值