-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: drag to set color (close: #47)
- Loading branch information
Showing
14 changed files
with
199 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<template> | ||
<div | ||
@dragover="handleDragover" | ||
@drop="handleDrop" | ||
@dragleave="over = false" | ||
:style="{ | ||
background: over ? '#eee' : 'white', | ||
}" | ||
> | ||
<field :name="name"> | ||
<el-color-picker v-model="color" size="small" /> | ||
</field> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Field from "./Field.vue"; | ||
export default { | ||
props: { | ||
name: String, | ||
value: String, | ||
}, | ||
components: { Field }, | ||
data() { | ||
return { | ||
over: false, | ||
}; | ||
}, | ||
computed: { | ||
color: { | ||
get() { | ||
return this.value; | ||
}, | ||
set(newColor) { | ||
this.$emit("input", newColor); | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
handleDragover(e) { | ||
e.preventDefault(); // 取消这个事件才能触发 drop 事件 | ||
this.over = true; | ||
}, | ||
handleDrop(e) { | ||
const color = e.dataTransfer.getData("drag-color"); | ||
this.$emit("input", color); | ||
}, | ||
}, | ||
}; | ||
</script> |
Oops, something went wrong.