Skip to content

Commit dfa5c65

Browse files
MissZhou12345Mz
andauthored
优化v-copy在http下不能复制的问题 (#517)
* fix: 修复顶级菜单无法被添加的问题 * optimize: v-copy的优化处理 --------- Co-authored-by: Mz <[email protected]>
1 parent 5459f4f commit dfa5c65

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

web/src/directives/copy/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ import Message from 'vue-m-message'
1414
export interface CopyElement extends HTMLElement {
1515
copyValue: string
1616
}
17-
17+
/**
18+
* eg.
19+
* 1、 v-copy="'copyContent'" // 默认是dblclick,localhost及https复制才会生效
20+
* 2、 v-copy:dblclick.legacy="'copyContent'" // 兼容模式,所有浏览器都生效
21+
*/
1822
export const copy = {
1923
mounted(el: CopyElement, binding: DirectiveBinding<string>) {
20-
const { isSupported, copy } = useClipboard()
21-
if (!isSupported.value) {
24+
const legacy = binding.modifiers?.legacy === true
25+
const { isSupported } = useClipboard()
26+
const { copy } = useClipboard({ legacy })
27+
if (!isSupported.value && !legacy) {
2228
throw new Error('[Directive: copy]: Your browser does not support Clipboard API')
2329
}
30+
2431
const { value } = binding
2532
if (value) {
2633
el.copyValue = value

0 commit comments

Comments
 (0)