<template>
<div id="example">
<input type="text" v-model="directiveCopy">
<button type="button" v-clipboard:copy="directiveCopy" v-clipboard:success="onSuccess" v-clipboard:error="onError">Copy!</button>
<input type="text" v-model="directiveCut">
<button type="button" v-clipboard:cut="directiveCut" v-clipboard:success="onSuccess" v-clipboard:error="onError">Cut!</button>
<input type="text" v-model="directCopy">
<button type="button" @click="onCopy(directCopy)">Copy!</button>
<input id="cutInput" type="text" v-model="directCut">
<button type="button" @click="onCut">Cut!</button>
</div>
</template>
<script>
export default {
name: 'example',
data() {
return {
directiveCopy: 'directiveCopy text',
directiveCut: 'directiveCut text',
directCopy: 'directCopy text',
directCut: 'directCut text'
}
},
methods: {
onSuccess(e) {
console.log(e)
},
onError(err) {
console.log(err)
},
onCopy(val) {
this.$copyText(val)
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
},
onCut() {
let element = this.$el.querySelector('#cutInput')
this.$cutText(element)
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
}
}
}
</script>