import { defineComponent, ref } from "vue";
import { message } from 'ant-design-vue';
import './index.scss'
export default defineComponent({
    name: "YdCopy",
    props: {
        value: {
            type: String,
            required: true,
        },

        text: {
            type: String,
            default: () => '复制'
        },

    },
    setup (prop, context) {
        const { value, text } = prop
        const copyInstance = ref(null)
        const copyValue = () => {
            // window.getSelection().selectAllChildren(copyInstance.value);
            copyInstance.value.select()
            document.execCommand("Copy");
            message.success('复制成功');
        }
        return () => (
            <span className='ydCopy' onClick={copyValue}>
                {text}
                <input ref={copyInstance} value={value} className='temp'> </input>
            </span>
        )
    }
});