1、安装依赖
npm install --save vue-clipboard2
2、用法:
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
3、项目中使用
<template>
<div>
<div style="text-align:center">
<span>{{message}}</span>
<mt-button type="primary" size="small" @click.native="handelAutoCopy" v-clipboard:copy="message" v-clipboard:success="onCopy" v-clipboard:error="onError">复制链接</mt-button>
</div>
</div>
</template>
<script>
data() {
return {
message:'文字啊文字啊'
};
},
components: {},
mounted() {},
methods: {
handelAutoCopy() {},
onCopy(e) {
Toast('已复制到粘贴板');
},
onError(e) {
Toast('无法复制');
}
},
computed: {},
}
</script>
<style lang='less' scoped>
</style>