100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > html表格点击为编辑框 el-table表格内双击或单击单元格编辑输入框 日期等

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

时间:2023-04-03 18:55:57

相关推荐

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: "-03-09"

},

{

id: 1,

name: "施工许可阶段",

planStartTime: "-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]

}

}

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。