Convert CopyCode component to Composition API (#124)
* Convert CopyCode component to Composition API * ^^/
This commit is contained in:
parent
92116273b0
commit
06d6cb6d19
@ -6,35 +6,24 @@
|
|||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
import { CheckIcon, ClipboardCopyIcon } from '@'
|
import { CheckIcon, ClipboardCopyIcon } from '@'
|
||||||
import { useVIntl, defineMessage } from '@vintl/vintl'
|
import { useVIntl, defineMessage } from '@vintl/vintl'
|
||||||
|
|
||||||
const copiedMessage = defineMessage({
|
const copiedMessage = defineMessage({
|
||||||
id: 'omorphia.component.copy.action.copy',
|
id: 'omorphia.component.copy.action.copy',
|
||||||
defaultMessage: 'Copy code to clipboard',
|
defaultMessage: 'Copy code to clipboard',
|
||||||
})
|
})
|
||||||
const { formatMessage } = useVIntl()
|
const { formatMessage } = useVIntl()
|
||||||
</script>
|
|
||||||
|
|
||||||
<script>
|
const props = defineProps<{ text: string }>()
|
||||||
export default {
|
|
||||||
props: {
|
const copied = ref(false)
|
||||||
text: {
|
|
||||||
type: String,
|
async function copyText() {
|
||||||
required: true,
|
await navigator.clipboard.writeText(props.text)
|
||||||
},
|
copied.value = true
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
copied: false,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async copyText() {
|
|
||||||
await navigator.clipboard.writeText(this.text)
|
|
||||||
this.copied = true
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user