/**
 * v-clipboard 剪切板
 */
import Vue from 'vue';
const clipboard = {
  bind(el, binding, vnode, oldVnode) {
    el.val = binding.value;
    el.handler = function() {
      const val = el.val;
      const input = document.createElement('input');
      el.appendChild(input);
      input.value = val;
      input.select();
      document.execCommand('Copy');
      Vue.prototype.$message({ type: 'success', message: '复制成功' });
      input.parentNode.removeChild(input);
    };
    el.addEventListener('click', el.handler);
  },
  update(el, binding, vnode, oldVnode) {
    el.val = binding.value;
  },
  unbind: function(el) {
    el.removeEventListener('click', el.handler);
  }
};
export default { clipboard };
