看了几篇文章,但是只感觉这个比较言简意赅

1。

先安装

npm install --save vue-clipboard2 or use dist/vue-clipboard.min.js 

2。

如果是npm,检查package.json是否安装成功

3。

npm run dev  启动一下。

4。

main.js添加

import Vue

import VueClipboard from 'vue-clipboard2'

Vue.use(VueClipboard)

5。

<template id="t">
  <div class="container">
    <input type="textv-model="message">
    <button type="button"
      v-clipboard:copy="message"
      v-clipboard:success="onCopy"
      v-clipboard:error="onError">Copy!</button>
  </div>
</template>
<script>
new Vue({
  el'#app',
  template'#t',
  datafunction ({
    return {
      message'Copy These Text'
    }
  },
  methods{
    onCopyfunction (e{
      alert('You just copied: e.text)
    },
    onErrorfunction (e{
      alert('Failed to copy texts')
    }
  }
})
</script>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
猜你喜欢
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案