js常用插件之vue-clipboard2复制粘贴
欢迎点击: 个人官网博客
使用方法简单
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.1/vue.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue-clipboard2/0.3.1/vue-clipboard.min.js"></script>
</head>
<body>
<div id="app">
<input type="text" v-model="copyUrl" />
<button type="button" v-clipboard:copy="copyUrl" v-clipboard:success="onCopy" v-clipboard:error="onError"> 复制链接
</button>
</div>
</body>
<script>
new Vue({
el: '#app',
data() {
return {
copyUrl: 'http://baidu.com'
}
},
methods: {
onCopy(e) {
console.log('复制成功!');
},
onError(e) {
console.log('复制失败!');
}
}
})
</script>
</html>