From 8f2c7d163e97da4d38e05e9a09d0d3d5ac5e1fb3 Mon Sep 17 00:00:00 2001 From: Inndy Date: Thu, 20 Apr 2017 14:10:39 +0800 Subject: [PATCH] Support v-clipboard:error --- vue-clipboard.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vue-clipboard.js b/vue-clipboard.js index 189b710..62d98ed 100644 --- a/vue-clipboard.js +++ b/vue-clipboard.js @@ -6,6 +6,8 @@ var VueClipboard = { bind: function (el, binding, vnode) { if(binding.arg === 'success') { el._v_clipboard_success = binding.value + } else if(binding.arg === 'error') { + el._v_clipboard_error = binding.value } else { var clipboard = new Clipboard(el, { text: function () { return binding.value }, @@ -15,12 +17,18 @@ var VueClipboard = { var callback = el._v_clipboard_success callback && callback(e) }) + clipboard.on('error', function (e) { + var callback = el._v_clipboard_error + callback && callback(e) + }) el._v_clipboard = clipboard } }, update: function (el, binding) { if(binding.arg === 'success') { el._v_clipboard_success = binding.value + } else if(binding.arg === 'error') { + el._v_clipboard_error = binding.value } else { el._v_clipboard.text = function () { return binding.value } el._v_clipboard.action = function () { return binding.arg === 'cut' ? 'cut' : 'copy' } @@ -29,6 +37,8 @@ var VueClipboard = { unbind: function (el, binding) { if(binding.arg === 'success') { delete el._v_clipboard_success + } else if(binding.arg === 'error') { + delete el._v_clipboard_error } else { el._v_clipboard.destroy() delete el._v_clipboard