onClickLeft() {
this.videoGroup = this.handleMove(0, this.currunt, this.videoGroup);
if (this.currunt != 0) {
this.currunt--;
}
},
onClickRight() {
this.videoGroup = this.handleMove(1, this.currunt, this.videoGroup);
if (this.currunt != this.videoGroup.length - 1) {
this.currunt++;
}
},
handleMove(status, index, arr) {
console.log(status, index);
// status: 0-表示上移|1-表示下移;index表示当前下标; arr数组
const data = JSON.parse(JSON.stringify(arr)); // 数组属于引入类型
console.log("dara", data);
if (status == 0) {
if (index == 0) {
// 上移第一项无需上移
this.$Message.warning("已经是第一个啦");
} else {
data.splice(index - 1, 2, data[index], data[index - 1]);
}
} else if (status == 1) {
// 下移最后一项无需下移
if (index != data.length - 1) {
data.splice(index, 2, data[index + 1], data[index]);
} else {
this.$Message.warning("已经是最后一个啦");
}
}
return data;
},
vue实现点击鼠标左右移动元素
最新推荐文章于 2024-07-18 15:04:08 发布