12345678910111213141516171819202122232425262728293031323334 |
- import Vue from 'vue'
- import Clipboard from 'clipboard'
- function clipboardSuccess(message) {
- if (!message) return
- Vue.prototype.$toast({
- message,
- type: 'success',
- duration: 1500,
- })
- }
- function clipboardError(message) {
- if (!message) return
- Vue.prototype.$toast({
- message: '复制失败',
- type: 'fail',
- })
- }
- export default function handleClipboard(text, event, message) {
- const clipboard = new Clipboard(event.target, {
- text: () => text,
- })
- clipboard.on('success', () => {
- clipboardSuccess(message)
- clipboard.destroy()
- })
- clipboard.on('error', () => {
- clipboardError()
- clipboard.destroy()
- })
- clipboard.onClick(event)
- }
|