首页 > 其他分享 >表格编辑时,根据这一行弹出层显示编辑界面,点击保存时发送请求,请求成功保存好数据到表达,请求错误,弹出提示

表格编辑时,根据这一行弹出层显示编辑界面,点击保存时发送请求,请求成功保存好数据到表达,请求错误,弹出提示

时间:2023-05-25 20:23:58浏览次数:45  
标签:axios 请求 保存 editedData 编辑 error response

这是一个网上的列子, 一表格,点击编辑时弹出层编辑这一行,点击保存时送请求的完整示例:
<template>
  <div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="role" label="角色"></el-table-column>
      <el-table-column prop="date" label="日期"></el-table-column>
      <el-table-column label="编辑">
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="dialogVisible">
      <el-form ref="form" :model="editedData">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="editedData.name"></el-input>
        </el-form-item>
        <el-form-item label="角色" prop="role">
          <el-input v-model="editedData.role"></el-input>
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-date-picker v-model="editedData.date" type="date"></el-date-picker>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleSave">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      tableData: [],
      dialogVisible: false,
      editedData: {
        name: '',
        role: '',
        date: ''
      }
    };
  },

  created() {
    this.fetchData();
  },

  methods: {
    fetchData() {
      // 发送请求获取表格数据
      axios.get('/api/tableData').then(response => {
        this.tableData = response.data;
      }).catch(error => {
        console.log(error);
      });
    },

    handleEdit(row) {
      // 弹出编辑窗口,并将当前行的数据赋值给 editedData
      this.editedData = Object.assign({}, row);
      this.dialogVisible = true;
    },

    handleSave() {
      // 发送保存请求
      axios.post('/api/saveData', this.editedData).then(response => {
        if (response.data.success) {
          // 请求成功,关闭编辑窗口并刷新表格数据
          this.dialogVisible = false;
          this.fetchData();
        } else {
          // 请求失败,提示操作错误
          this.$message.error('操作失败,请稍后重试!');
        }
      }).catch(error => {
        console.log(error);
      });
    }
  }
};
</script>

 

标签:axios,请求,保存,editedData,编辑,error,response
From: https://www.cnblogs.com/fgxwan/p/17432738.html

相关文章

  • GET请求如何传递数组参数
    方式一可以将数组参数传递多次,springmvc会将多个同名参数自动封装成数组或者集合对象,示例如下: #请求URLhttp://127.0.0.1:8080/getUsers?name=张三&name=李四#后台接口代码@RestController@RequestMapping("/")publicclassSpringMvcController{@RequestMapping(v......
  • 支持复制粘贴word公式的文本编辑器
    ​ 图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码目前限chrome浏览器使用首先以um-editor的二进制流保存为例:打开umeditor.js,找到UM.plugins['autoupload'],然后找到autoUploadHandler方法,注释掉其中的代码。加入下面的代码://判断剪......
  • springboot aspect 对请求参数,返回数据加密
        对客户端<--->服务端传输数据加密。  上送文件流不加密,其他信息加密。  返回信息加密。 切面的方式进行解密,不修改业务逻辑。   找到对应的方法,对应的参数,进行解密。@Around("@annotation(com.jiayingsoft.scip.annotation.ScipSecureityMethodAtn......
  • 支持复制粘贴word公式的Web编辑器
    ​ 这种方法是servlet,编写好在web.xml里配置servlet-class和servlet-mapping即可使用后台(服务端)java服务代码:(上传至ROOT/lqxcPics文件夹下)<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@     page contentType="text/html;cha......
  • HTTP - HTTP请求 与 HTTP响应 【Web后端开发基础】
    一、HTTP介绍HTTP(HyperTextTransferProtocol)超文本传输协议,是互联网上应用最为广泛的一种网络协议。 作用: 规范浏览器和服务器之间通信时传输数据的格式 特点: 基于TCP协议:面向连接,安全 基于请求-响应模型的:一次请求对应一次响应 HTTP协议是无状态的......
  • 第三方接口控制请求时间处理
    问题项目中需要调用第三方接口,若第三方接口在X秒内未返回,则继续后续业务操作代码展示publicclassCheckTimeOutDemo{privatestaticExecutorServicethreadService=newThreadPoolExecutor(0,20,60L,TimeUnit.SECONDS,newSynchronousQueue<>(),r->{......
  • 报错问题:谷粒商城关于pubsub、publish报错,无法发送查询品牌信息的请求
    1、npminstall--savepubsub-js2、在src下的main.js中引用:①importPubSubfrom'pubsub-js'②Vue.prototype.PubSub=PubSub ......
  • 转载:PageOffice调用本地office实现多人在线同时编辑Word文档
    说明:多人同时在线编辑文件大多数会出现文档相互覆盖的问题,后保存的文档会覆盖先保存的文档。pageoffice的这个功能可以用程序控制不同用户打开文件后,编辑Word文档中属于自己的区域,并且不会互相影响。1、环境:前端:vue后端:springboot、pageoffice5.4.0.3版本vue+springboot集成......
  • element_ui实现表格内套表单,点击可以编辑
    <template><divclass="app-container"><el-table:data="list"stripestyle="width:100%"@cell-dblclick="openEditColumn"><el-table-columnprop="cameraX"label="坐标位置:X&qu......
  • 【习题 6】保存应用数据 答案
    【习题6】保存应用数据判断题1.首选项是关系型数据库。正确(True)错误(False)2.应用中涉及到Student信息,如包含姓名,性别,年龄,身高等信息可以用首选项来存储。正确(True)错误(False)3.同一应用或进程中每个文件仅存在一个Preferences实例。正确(True)错误(Fal......