Skip to content

Commit

Permalink
feat: 引入剪贴板工具
Browse files Browse the repository at this point in the history
  • Loading branch information
cadecode committed Apr 20, 2023
1 parent 01cbeb4 commit 93ecb5a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"axios": "0.18.1",
"clipboard": "^2.0.4",
"core-js": "3.6.5",
"element-ui": "2.13.2",
"js-cookie": "2.2.0",
Expand Down
32 changes: 32 additions & 0 deletions src/util/clipboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Clipboard from 'clipboard';
import {Message} from 'element-ui';

function clipboardSuccess() {
Message({
message: '已复制',
type: 'success',
duration: 1500
});
}

function clipboardError() {
Message({
message: '复制失败',
type: 'error'
});
}

export default function handleClipboard(text, event) {
const clipboard = new Clipboard(event.target, {
text: () => text
});
clipboard.on('success', () => {
clipboardSuccess();
clipboard.destroy();
});
clipboard.on('error', () => {
clipboardError();
clipboard.destroy();
});
clipboard.onClick(event);
}

0 comments on commit 93ecb5a

Please sign in to comment.