diff --git a/src/directives/modules/custom.ts b/src/directives/modules/custom.ts index 3711cd7..3d582c6 100644 --- a/src/directives/modules/custom.ts +++ b/src/directives/modules/custom.ts @@ -1,8 +1,15 @@ import { Directive } from "vue"; const custom: Directive = { - mounted(el, binding) { - el.style.color = binding.value; + mounted(el, binding, vnode) { + el.__onClick__ = () => { + binding.value(vnode.props); + }; + el.addEventListener("click", el.__onClick__); + }, + beforeUnmount(el) { + // 解绑dom上的点击事件 + el.removeEventListener("click", el.__onClick__); } }; diff --git a/src/views/custom-instruction/test-instruction/test-instruction.vue b/src/views/custom-instruction/test-instruction/test-instruction.vue index 16352b5..2a393a1 100644 --- a/src/views/custom-instruction/test-instruction/test-instruction.vue +++ b/src/views/custom-instruction/test-instruction/test-instruction.vue @@ -1,9 +1,18 @@ - +