有关 editRowIndex cloneEditRowIndex 的问题

来源:6-8 表格组件-实现可编辑行功能-1

johnny_2008

2023-02-02

老师您好
1、请问这两个属性是做什么用的,如果是判断只有点击了编辑按钮才能进入编辑状态,那单独拷贝一份按钮标识的目的是?
2、日志显示的值只有两种结果,edit空字符
3、点击删除按钮,会进入行编辑状态

疑惑的代码

	// 拷贝一份按钮的标识
	let cloneEditRowIndex = ref<string>(props.editRowIndex);
	// 点击行的事件
	let rowClick = (row: any, column: any) => {
	  if (column.label === actionOption.value!.label) {
	    if (props.isEditRow && cloneEditRowIndex.value === props.editRowIndex) {
	    // cloneEditRowIndex.value === props.editRowIndex 此处的判断结果始终为 true
	      row.rowEdit = !row.rowEdit;
	      tableData.value.map((item) => {
	        if (item !== row) item.rowEdit = false;
	      });
	      if (!row.rowEdit) emits("update:editRowIndex", "");
	    }
	  }
	};

按照需求,对代码的调整,请您指教
1、移除 cloneEditRowIndex 变量,对所有操作项添加 actionName
2、修改 rowClick 方法

let rowClick = (row: any, column: any) => {
  if (column.label === actionOption.value!.label) {
    if (props.isEditRow) {
      tableData.value.forEach((item) => {
        if (props.editRowIndex === "row-edit" && row === item) {
          item.rowEdit = true;
        } else {
          item.rowEdit = false;
        }
      });
    }
  }
};
写回答

1回答

五月的夏天

2024-12-30

拷贝的目的是不改变原有变量,因为传递的值改变了,可能会影响父组件的数据

0
0

基于Vue3+Vite+TS,二次封装element-plus业务组件

集成大量实际样例,系统掌握前沿技术栈与二次组件库封装能力

455 学习 · 204 问题

查看课程