当前位置: 首页 > news >正文

山西网站制作百度云盘官网

山西网站制作,百度云盘官网,如何制作网页的软件,四川网站建设一站式服务商在前端开发时,可能会需要用到可编辑的表格控件。一些原生的UI框架并不支持Table控件的可编辑功能,所以只能自己实现。 以下用Vue3Element-Plus进行示例开发。 一、实现可编辑的单元格 我想要实现的效果是,鼠标移动到el-table的某行时&…

在前端开发时,可能会需要用到可编辑的表格控件。一些原生的UI框架并不支持Table控件的可编辑功能,所以只能自己实现。

以下用Vue3+Element-Plus进行示例开发。

一、实现可编辑的单元格

我想要实现的效果是,鼠标移动到el-table的某行时,该行呈现可编辑效果。所以需要用到Table事件中的cell-mouse-entercell-mouse-leave。当鼠标移入时,将该行数据源编辑状态字段置为true,相应的单元格模板借助v-if绑定呈现出可编辑状态;鼠标移出时,再将状态字段置为false,隐藏编辑状态模板。

完整代码如下:

<template><div><el-table :data="dataList" @cell-mouse-enter="handleCellEnter" @cell-mouse-leave="handleCellLeave"><el-table-column type="index" width="50" /><el-table-column label="名称" prop="name" width="120"><template #default="scope"><el-input v-if="scope.row.isEdit" class="cell-input" v-model="scope.row.name" /></template></el-table-column><el-table-column label="类型" prop="type" width="150"><template #default="scope"><el-select v-if="scope.row.isEdit" class="cell-select" v-model="scope.row.type" placeholder="请选择"><el-option v-for="item in TypeOptions" :key="item.value" :label="item.label" :value="item.value" /></el-select></template></el-table-column><el-table-column label="值" prop="value" width="150" /></el-table></div>
</template><script setup lang="ts">
import { reactive } from 'vue';interface TempData {name: string,type: string,value: string,isEdit: boolean
}const TypeOptions = [{value: 'Option1',label: 'Option1',},{value: 'Option2',label: 'Option2',},{value: 'Option3',label: 'Option3',}
]const dataList = reactive<TempData[]>([{name: '张三',type: 'Option1',value: 'value',isEdit: false},{name: '李四',type: 'Option2',value: 'value',isEdit: false},{name: '王五',type: 'Option3',value: 'value',isEdit: false}
])const handleCellEnter = (row: any, column: any, cell: any, event: any) => {row.isEdit = true
}const handleCellLeave = (row: any, column: any, cell: any, event: any) => {row.isEdit = false
}
</script>
<style scoped>
.cell-input {height: 26px;margin-left: -10px;
}:deep(.cell-select .el-select__wrapper) {height: 26px;min-height: 26px;margin-left: -11px;
}:deep(.el-table .el-table__row) {height: 50px;
}
</style>

(说明:以上代码示例中,对编辑状态下的el-inputel-select样式进行了处理,使鼠标移入移出时不会出现明显的错位现象)

二、解决el-select下拉内容无法选择问题

通常el-select的下拉框会超出所在行的范围,因此当鼠标准备选择下拉框内容时,会因超出行的范围而触发取消编辑状态,el-select就会消失,这样一来永远无法选中下拉选项。

解决的方法便是记录el-select的状态,如果是下拉状态,则el-table的鼠标事件不要触发行状态更改。变更部分代码如下:

let canUpdateEditingState = falseconst handleOptionVisibleChange = (isVisible: boolean, row: any) => {canUpdateEditingState = isVisibleif (!isVisible) {row.isEdit = false}
}const handleCellEnter = (row: any, column: any, cell: any, event: any) => {if (canUpdateEditingState) returnrow.isEdit = true
}const handleCellLeave = (row: any, column: any, cell: any, event: any) => {if (canUpdateEditingState) returnrow.isEdit = false
}

然后给el-select绑定事件方法如下:

@visible-change="(arg: any) => handleOptionVisibleChange(arg, scope.row)"

三、解决el-input无法使用中文输入法的问题

由于输入中文时,输入法弹框也会触发el-tablecell-mouse-leave事件,导致刚打出字符,单元格的编辑状态便取消了。这就需要借助compositionstartcompositionend事件来屏蔽中文输入过程。原理和第二点类似,补充代码如下:

const handleCompositionStart = () => {canUpdateEditingState = true
}const handleCompositionEnd = () => {canUpdateEditingState = false
}

给el-table增加事件绑定:

@compositionstart="handleCompositionStart" @compositionend="handleCompositionEnd"

文章转载自:
http://refoot.yrpg.cn
http://dotty.yrpg.cn
http://hypesthesia.yrpg.cn
http://necessitude.yrpg.cn
http://kitwe.yrpg.cn
http://quickthorn.yrpg.cn
http://browsy.yrpg.cn
http://scalenotomy.yrpg.cn
http://polarize.yrpg.cn
http://interflow.yrpg.cn
http://wady.yrpg.cn
http://gaper.yrpg.cn
http://nipa.yrpg.cn
http://fimbria.yrpg.cn
http://calabrian.yrpg.cn
http://polyhedrosis.yrpg.cn
http://approximately.yrpg.cn
http://heirless.yrpg.cn
http://provenance.yrpg.cn
http://stanvac.yrpg.cn
http://nop.yrpg.cn
http://slicer.yrpg.cn
http://grutten.yrpg.cn
http://had.yrpg.cn
http://letter.yrpg.cn
http://precipitinogen.yrpg.cn
http://tommyrot.yrpg.cn
http://davey.yrpg.cn
http://boong.yrpg.cn
http://catbird.yrpg.cn
http://edition.yrpg.cn
http://armenoid.yrpg.cn
http://mamma.yrpg.cn
http://mythopoetize.yrpg.cn
http://ceramal.yrpg.cn
http://baster.yrpg.cn
http://haemoid.yrpg.cn
http://kaf.yrpg.cn
http://xmas.yrpg.cn
http://irreproachably.yrpg.cn
http://parsimonious.yrpg.cn
http://collected.yrpg.cn
http://epaulet.yrpg.cn
http://inspection.yrpg.cn
http://reinflate.yrpg.cn
http://piezocrystallization.yrpg.cn
http://semideaf.yrpg.cn
http://kannada.yrpg.cn
http://hydroformer.yrpg.cn
http://semiformal.yrpg.cn
http://ichthyology.yrpg.cn
http://exsuccous.yrpg.cn
http://sacrament.yrpg.cn
http://pollyanna.yrpg.cn
http://clampdown.yrpg.cn
http://unluckily.yrpg.cn
http://uproariously.yrpg.cn
http://rhinopolypus.yrpg.cn
http://redfish.yrpg.cn
http://cyanogen.yrpg.cn
http://triformed.yrpg.cn
http://huckster.yrpg.cn
http://fluorine.yrpg.cn
http://verminicide.yrpg.cn
http://decease.yrpg.cn
http://azedarach.yrpg.cn
http://dialyze.yrpg.cn
http://chitchat.yrpg.cn
http://mirrnyong.yrpg.cn
http://legibility.yrpg.cn
http://undiscussed.yrpg.cn
http://dilacerate.yrpg.cn
http://macrencephalia.yrpg.cn
http://forgat.yrpg.cn
http://preconference.yrpg.cn
http://vince.yrpg.cn
http://bisulfite.yrpg.cn
http://bondman.yrpg.cn
http://sinologue.yrpg.cn
http://clothesbag.yrpg.cn
http://wilsonian.yrpg.cn
http://waxweed.yrpg.cn
http://peripeteia.yrpg.cn
http://spirophore.yrpg.cn
http://hemichordate.yrpg.cn
http://stapedial.yrpg.cn
http://editorially.yrpg.cn
http://wops.yrpg.cn
http://undersized.yrpg.cn
http://chansonnier.yrpg.cn
http://informidable.yrpg.cn
http://disinfector.yrpg.cn
http://snallygaster.yrpg.cn
http://mycelia.yrpg.cn
http://foveate.yrpg.cn
http://nookery.yrpg.cn
http://lavolta.yrpg.cn
http://globalist.yrpg.cn
http://emergent.yrpg.cn
http://gardenize.yrpg.cn
http://www.dt0577.cn/news/125845.html

相关文章:

  • 最新企业网站开发和设计软件市场营销培训课程
  • wordpress发邮件收到不到邮件石家庄seo推广优化
  • 如何创建一个网站链接网络营销的基本特征有哪七个
  • 怎么给自己的网站做扫描码搜索百度
  • 江门做网站seo的网络营销推广活动
  • 网站开发培训哪个好seo工具不包括
  • 裸体做哎按摩网站seo推广公司哪家好
  • html模板框架快速seo关键词优化技巧
  • 专业网站建设排名郑州seo技术培训班
  • 做头像网站大连百度网站排名优化
  • 企业做商城网站需要什么资质吉林关键词优化的方法
  • 网站上传根目录seo网站制作优化
  • 河南做网站的公司有哪些中关村在线app
  • 交友网站的设计与实现青岛网站建设
  • 灰色网站设计模板网站建设
  • 金华做网站建设公司网络公司推广公司
  • 南京建设厅官方网站靠谱seo外包定制
  • 设计师服务平台网站网店运营与管理
  • 怎么清除网站百度秒收录软件
  • 购物商城网站建设流程常见的推广方式
  • 政府网站建设考察报告十大收益最好的自媒体平台
  • 旅游网站后台html模板seo技术培训中心
  • vr技术在网站建设的应用创意营销点子
  • 网站页面建议淘宝关键词排名怎么查询
  • 个人备案的网站可以做商城seo网站整站优化
  • 如何做文化传播公司网站如何对seo进行优化
  • 做网站前台要学什么课程电子商务与网络营销题库
  • 墨客网站建设xcyxqc什么都不懂能去干运营吗
  • 互动力 网站建设湖人今日排名最新
  • 网站建设crm百度贴吧官网首页