欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

html表格点击为编辑框,el-table表格内双击或单击单元格编辑输入框、日期等

发布时间:2024/9/30 编程问答 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 html表格点击为编辑框,el-table表格内双击或单击单元格编辑输入框、日期等 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

需求

在el-table中想要直接点击单元格直接由文字显示变为编辑框状态,而非一整行编辑或者通过展示模态框编辑,这样目标性会比较清楚且页面较简洁。下面直接上代码!

实现效果

html代码

@blur='blurInput(scope.row.id,"name",scope.row.name)' v-focus>

{{scope.row.name}}

type="date" :clearable="false" value-format="yyyy-MM-dd" placeholder="请选择开始日期"

@blur='blurInput(scope.row.id,"planStartTime",scope.row.planStartTime)' v-focus>

{{scope.row.planStartTime}}

js代码

export default {

data() {

return {

//表格数据

tableList: [

{

id: 0,

name: "规划许可阶段",

planStartTime: "2021-03-09"

},

{

id: 1,

name: "施工许可阶段",

planStartTime: "2021-03-09"

}

],

showInput: "",

oldData: {}

}

},

directives: {

// 通过自定义指令实现的表单自动获得光标的操作

focus: {

inserted: function(el) {

if (el.tagName.toLocaleLowerCase() == "input") {

el.focus()

} else {

if (el.getElementsByTagName("input")) {

el.getElementsByTagName("input")[0].focus()

}

}

el.focus()

}

},

focusTextarea: {

inserted: function(el) {

if (el.tagName.toLocaleLowerCase() == "textarea") {

el.focus()

} else {

if (el.getElementsByTagName("textarea")) {

el.getElementsByTagName("textarea")[0].focus()

}

}

el.focus()

}

}

},

// 方法

methods: {

// 当input失去光标后进行的操作

async blurInput(id, name, value) {

let obj = {}

// 判断数据是否有所改变,如果数据有改变则调用修改接口

if (this.oldData[name] != value) {

obj[name] = value //被改变的数据

// 然后再写调用接口,提交内容的东西就可以了

console.log("===值改变了")

}

this.showInput = ""

},

/*

方法参数皆为框架方法的默认传参

row 行数据

column 被点击的触发了方法的单元格

event 事件

*/

tableDbEdit(row, column, event) {

this.showInput = column.property + row.id

this.oldData[column.property] = row[column.property]

}

}

}

总结

以上是生活随笔为你收集整理的html表格点击为编辑框,el-table表格内双击或单击单元格编辑输入框、日期等的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。