<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: mayako
 * @Date: 2020-02-05 14:47:35
 * @LastEditors  : mayako
 * @LastEditTime : 2020-02-05 15:01:33
 -->
<template>
  <div @click="handleClick" ><slot>{{ caption }}</slot></div>
</template>

<script>

import copySelect from '../../../src/utils/copy-select';

export default {
  name: 'DaoClipboard',
  componentName: 'DaoClipboard',
  props: {
    caption: String,
    content: String,
    onSuccess: {
      type: Function,
      default() {
        return () => 0;
      }
    },
    onError: {
      type: Function,
      default() {
        return () => 0;
      }
    }
  },

  data() {
    return {
    };
  },
  methods: {
    handleClick() {
      copySelect(this.$el, this.content, (succeed) => {
        this.callback(succeed);
      });
    },
    callback(succeed) {
      if (succeed) {
        this.onSuccess();
      } else {
        this.onError();
      }
    }
  }
};
</script>
