fe-drone-ci/src/utils/clipboard.js

37 lines
741 B
JavaScript
Raw Normal View History

2017-09-27 02:03:42 +00:00
import Vue from 'vue'
2017-11-17 09:51:41 +00:00
import Clipboard from 'clipboard'
2017-09-27 02:03:42 +00:00
function clipboardSuccess() {
Vue.prototype.$message({
message: '复制成功',
type: 'success',
duration: 1500
})
}
function clipboardError() {
Vue.prototype.$message({
message: '复制失败',
type: 'error'
})
}
export default function handleClipboard(text, event) {
const clipboard = new Clipboard(event.target, {
text: () => text
})
clipboard.on('success', () => {
clipboardSuccess()
clipboard.off('error')
clipboard.off('success')
clipboard.destroy()
})
clipboard.on('error', () => {
clipboardError()
clipboard.off('error')
clipboard.off('success')
clipboard.destroy()
})
clipboard.onClick(event)
}