Files
crawler-plugin/admin-frontend-vue/src/components/CopyText.vue
T

28 lines
691 B
Vue

<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { copyFeedback, isCopySupported } from './copy-model'
const props = defineProps<{ text: string }>()
async function handleCopy(): Promise<void> {
if (!props.text || !isCopySupported()) {
ElMessage.warning(copyFeedback(''))
return
}
try {
await navigator.clipboard.writeText(props.text)
ElMessage.success(copyFeedback(props.text))
} catch {
ElMessage.error(copyFeedback(''))
}
}
</script>
<template>
<span class="copy-text" role="button" tabindex="0" :title="text" @click="handleCopy"><slot>{{ text }}</slot></span>
</template>
<style scoped>
.copy-text { cursor: pointer; }
</style>