Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
vue-clipboard2
Advanced tools
A simple vuejs 2 binding for clipboard.js
npm install --save vue-clipboard2
or use dist/vue-clipboard.min.js
without webpack
For vue-cli user:
import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
For standalone usage:
<script src="vue.min.js"></script>
<!-- must place this line after vue.js -->
<script src="dist/vue-clipboard.min.js"></script>
Yes, you can do it by using our new method: this.$copyText
. See
sample2,
where we replace the clipboard directives with a v-on directive.
Modern browsers have some limitations like that you can't use window.open
without a user interaction.
So there's the same restriction on copying things! Test it before you use it. Make sure you are not
using this method inside any async method.
Before using this feature, read: this issue and this page first.
See clipboardjs document and this pull request, container
option is available like this:
let container = this.$refs.container
this.$copyText("Text to copy", container)
Or you can let vue-clipboard2
set container
to current element by doing this:
import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'
VueClipboard.config.autoSetContainer = true // add this line
Vue.use(VueClipboard)
<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>
<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>
You can use your Vue instance vm.$el
to get DOM elements via the usual traversal methods, e.g.:
this.$el.children[1].children[2].textContent
This will allow you to access the rendered content of your components, rather than the components themselves.
PRs welcome, and issues as well! If you want any feature that we don't have currently, please fire an issue for a feature request.
FAQs
A Vuejs2 & Vuejs3 binding for clipboard.js
The npm package vue-clipboard2 receives a total of 93,755 weekly downloads. As such, vue-clipboard2 popularity was classified as popular.
We found that vue-clipboard2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.