element-ui el-transfer添加拖拽排序功能
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
// html 部分
<el-card class="box-card">
<el-transfer
:render-content="renderFunc"
v-model="value"
:data="data"
:titles="['未选中栏', '已选中栏']"
>
</el-transfer>
<div class="btnClass">
<el-button size="small" type="primary" @click="submit()">提交</el-button>
</div>
</el-card>
// js部分
value: number[] = []
data: Array<{ sort: number, key: number, label: string}> = [
{ sort: 1, key: 5001, label: '序号' },
{ sort: 2, key: 5002, label: '告警编号' },
{ sort: 3, key: 5003, label: '告警序号' },
{ sort: 4, key: 5004, label: '告警时间' },
{ sort: 5, key: 5005, label: '告警类型' }
]
formIndex: number = -1
formOption: any = null
// 官方的推荐写法中,renderFunc使用的jsx来写的,但是在vue2中使用jsx语法试了几次都不能通过ts的规则校验,
// 于是改用render
renderFunc(h, option) {
let temp = `${option.label}`
return h('span', {
on: {
'dragstart': ($event) => {
this.formIndex = $event.target.__vue__.option.sort -1
this.formOption = $event.target.__vue__.option
},
'dragover': ($event) => {
$event.preventDefault();
$event.dataTransfer.effectAllowed = "move";
},
'drop': ($event) => {
let source = {
sort: $event.target.__vue__.option.sort,
key: this.formOption.key,
label: this.formOption.label
}
let target = {
sort: this.formIndex + 1,
key: $event.target.__vue__.option.key,
label: $event.target.__vue__.option.label
}
this.$set(this.data, this.formIndex, target)
this.$set(this.data, $event.target.__vue__.option.sort -1, source)
}
},
attrs: {
draggable: true
}
}, temp)
}
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)