vue-vben-admin/src/views/demo/feat/copy/index.vue

40 lines
1.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="p-4">
<CollapseContainer class="px-20 bg-white w-full h-32 rounded-md" title="Copy Example">
<div class="flex justify-center">
<a-input placeholder="请输入" v-model:value="value" />
<a-button type="primary" @click="handleCopy">Copy</a-button>
</div>
</CollapseContainer>
</div>
</template>
<script lang="ts">
import { defineComponent, unref, ref } from 'vue';
import { CollapseContainer } from '/@/components/Container/index';
import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
import { useMessage } from '/@/hooks/web/useMessage';
export default defineComponent({
name: 'Copy',
components: { CollapseContainer },
setup() {
const valueRef = ref('');
const { createMessage } = useMessage();
const { clipboardRef, copiedRef } = useCopyToClipboard();
function handleCopy() {
const value = unref(valueRef);
if (!value) {
createMessage.warning('请输入要拷贝的内容!');
return;
}
clipboardRef.value = value;
if (unref(copiedRef)) {
createMessage.warning('copy success');
}
}
return { handleCopy, value: valueRef };
},
});
</script>