工具与UI
plugin
* @Description:
返回目录<!--
- @Description:
- @Author: Huang junbang
- @Date: 2020-03-23 15:37:32
- @LastEditTime: 2020-05-26 16:42:19
- @LastEditors: Huang junbang
-->
一、 vue-clipboard2 复制内容到剪切板
clipboard.js中文网
vue-clipboard2 npm
1. 安装引用
npm install --save vue-clipboard2
import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)2. 使用方法一
<div id="app"></div>
<template id="t">
<div class="container">
<input type="text" v-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',
data: function () {
return {
message: 'Copy These Text'
}
},
methods: {
onCopy: function (e) {
alert('You just copied: ' + e.text)
},
onError: function (e) {
alert('Failed to copy texts')
}
}
})
</script>3. 使用方法二
<div id="app"></div>
<template id="t">
<div class="container">
<input type="text" v-model="message">
<button type="button" @click="doCopy">Copy!</button>
</div>
</template>
<script>
new Vue({
el: '#app',
template: '#t',
data: function () {
return {
message: 'Copy These Text'
}
},
methods: {
doCopy: function () {
this.$copyText(this.message).then(function (e) {
alert('Copied')
console.log(e)
}, function (e) {
alert('Can not copy')
console.log(e)
})
}
}
})
</script>