diff --git a/packages/vant-cli/site/common/index.js b/packages/vant-cli/site/common/index.js index 0da499ee8..dcfb367e9 100644 --- a/packages/vant-cli/site/common/index.js +++ b/packages/vant-cli/site/common/index.js @@ -8,4 +8,31 @@ export function decamelize(str, sep = '-') { .toLowerCase(); } +// from https://30secondsofcode.org +export function copyToClipboard(str) { + const el = document.createElement('textarea'); + el.value = str; + el.setAttribute('readonly', ''); + el.style.position = 'absolute'; + el.style.left = '-9999px'; + document.body.appendChild(el); + + const selection = document.getSelection(); + + if (!selection) { + return; + } + + const selected = selection.rangeCount > 0 ? selection.getRangeAt(0) : false; + + el.select(); + document.execCommand('copy'); + document.body.removeChild(el); + + if (selected) { + selection.removeAllRanges(); + selection.addRange(selected); + } +} + export { isMobile }; diff --git a/packages/vant-cli/site/desktop/components/Content.vue b/packages/vant-cli/site/desktop/components/Content.vue index af2b014c2..279e69b14 100644 --- a/packages/vant-cli/site/desktop/components/Content.vue +++ b/packages/vant-cli/site/desktop/components/Content.vue @@ -8,32 +8,7 @@