如何利用vuejs
实现一个像element-ui
插件一个穿梭框左右拖拽的功能,下面web建站小编给大家介绍一下!
template代码如下:
<template> <div> <h3 style="text-align: center">拖拽穿梭框</h3> <div id="home" @mousemove="mousemove($event)"> <div class="tree-select-content"> <span class="select-content" :id="'mouse' + index" v-for="(item, index) in leftData" :key="item.id" @mousedown="mousedown(index, 1)" @mouseup="mouseup(item, 1, index)" > <span class="select-text">{{ item.label }}</span> <span class="select-text-X" @click="handerClickX(item, index, 1)" >X</span > </span> </div> <div class="tree-select-content"> <span class="select-content" :id="'deleteMouse' + index" v-for="(item, index) in rightData" :key="item.id" @mousedown="mousedown(index, 2)" @mouseup="mouseup(item, 2, index)" > <span class="select-text">{{ item.label }}</span> <span class="select-text-X" @click="handerClickX(item, index, 2)" >X</span > </span> </div> </div> </div> </template>
js代码如下:
export default { name: "home", data() { return { leftData: [ { label: "中国", id: 1 }, { label: "美国", id: 2 }, { label: "英国", id: 3 }, { label: "法国", id: 4 }, { label: "荷兰", id: 5 }, ], rightData: [{ label: "世界", id: 6 }], isMoveTrue: false, isMove: false, moveId: "", }; }, methods: { mousedown(index, val) { this.isMoveTrue = true; if (val == 1) { this.moveId = "mouse" + index; } else { this.moveId = "deleteMouse" + index; } }, mousemove(event) { if (this.isMoveTrue) { this.isMove = true; document.getElementById(this.moveId).style.position = "absolute"; document.getElementById(this.moveId).style.top = event.clientY + "px"; document.getElementById(this.moveId).style.left = event.clientX + "px"; document.getElementById(this.moveId).style.transform = "translate(-50%,-50%)"; } }, mouseup(item, val, index) { if (!this.isMove) { this.isMoveTrue = false; this.moveId = ""; } if (this.isMoveTrue && val == 2) { this.$nextTick(() => { this.rightData.splice(index, 1); this.leftData.push(item); }); } else if (this.isMoveTrue && val) { this.leftData.splice(index, 1); this.rightData.push(item); } document.getElementById(this.moveId).style.display = "none"; this.isMoveTrue = false; this.isMove = false; this.moveId = ""; }, handerClickX(item, index, val) { if (val == 1) { this.leftData.splice(index, 1); this.rightData.push(item); } else { this.rightData.splice(index, 1); this.leftData.push(item); } }, }, };
css样式
#home { display: flex; justify-content: space-around; } .tree-select-content { width: 40%; height: 300px; background: #f9faff; border: 1px solid #dee0ec; border-radius: 4px; display: flex; flex-wrap: wrap; align-content: baseline; } .select-content { width: max-content; height: 20px; padding: 1.6%; border: 1px solid #d6dbed; margin: 2% 1% 0; background: #ffffff; box-shadow: 0 0 8px 0 rgba(72, 119, 236, 0.1); border-radius: 4px; } .select-content:hover span { color: #4877ec; } .select-content:hover { cursor: pointer; background: #f8faff; border: 1px solid #3e75f4; } .select-text { font-size: 15px; color: #2e2f36; text-align: center; font-weight: 400; } .select-text-X { font-size: 15px; color: #4877ec; letter-spacing: 0; font-weight: 400; margin-left: 12px; cursor: pointer; }
上面是“vuejs如何实现穿梭框左右拖拽(附代码)”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2502.html
workflows工作流
- 一尊白玉佛像ComfyUI工作流
- 羚羊安上小白兔的门牙ComfyUI工作流
- 一只由水晶制成的蜂鸟
- 池塘边的大熊猫ComfyUI工作流
- 一群可爱的小老鼠ComfyUI工作流
- 3d卡通风格多彩头发的女人
- 晚上樱花狐狸ComfyUI工作流
- 一艘来自工业时代的飞船ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!