This website requires JavaScript.
BING
Because the mountain is there
OG

极简的剪切板组件

716 words, 2 min read2018/01/05 PM4,552 views

不再用 clipboard.js 了,所以:

          
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
<!-- 这就是剪贴板载体,想办法视觉隐藏就可以 --> <input type="text" v-model="clipboardText" class="clipboard-input" ref="clipboard"> <button @click="copyToClipboard('123')"></button> <button @click="copyToClipboard('abc')"></button> <button @click="copyToClipboard('789')"></button>
          
  • 1
  • 2
  • 3
  • 4
.clipboard-input { height: 0px; opacity: 0; }
          
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
export default { data() { return { clipboardText: '' } }, methods: { copyToClipboard(text) { console.log('要复制这个文本:', text) this.clipboardText = text // $nextTick 在这里没用 setTimeout(() => { this.$refs.clipboard.select() document.execCommand('Copy') }) } } }

好,完

Creative Commons BY-NC 4.0https://surmon.me/article/80
8 / 8 comments
Guest
Join the discussion...
  • Superficial
    Superficial🇨🇳CNWuhanWindowsChrome
    #1823

    大佬, 太强大了, 👍

  • channg
    Channg🇨🇳CNBeijingWindowsChrome
    #811
  • Zzhiren
    Zzhiren🇨🇳CNHangzhouWindowsChrome
    #634

    666666

  • 11
    11🇨🇳CNXinminWindowsChrome
    #628

    11

    • 121
      121🇨🇳CNXinminWindowsChrome
      #629

      reply:

      回复1

  • Yunzhuiyue
    Yunzhuiyue🇨🇳CNQingdaoWindowsChrome
    #614
              
    • 1
    alert('NB');
    • Surmon
      Surmon🇨🇳CNXiamenMac OSChrome
      #618

      reply:

      爱你

  • Jkchao
    Jkchao🇹🇼TWPingzhenMac OSChrome
    #612
              
    • 1
    • 2
    console.log('666')