Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
* Update README

fix typos, add $copyText example from sample2, close #28
  • Loading branch information
jamessouth authored and Inndy committed May 17, 2018
1 parent 1dee3d7 commit b08f3b4
Showing 1 changed file with 49 additions and 6 deletions.
55 changes: 49 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,63 @@ new Vue({

## I want to copy texts without a specific button!

Yes, you can do it by using our new method: `this.$copyText`. see [sample2](sample2.html).
Yes, you can do it by using our new method: `this.$copyText`. See [sample2](sample2.html), where we replace the clipboard directives with a v-on directive.

Modern browser have some limiation like that you can't use `window.open` without a user iteraction.
So there's a same restriction on copy things! Test it before you use it. Make sure you are not
## Sample 2

```html
<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```](https://vuejs.org/v2/api/#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.

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, reading
Before using this feature, read:
[this issue](https://github.com/zenorocha/clipboard.js/issues/218) and
[this page](https://github.com/zenorocha/clipboard.js/wiki/Known-Limitations) first.

### Contribution

PRs welcome, and issues aswell! If you want any feature that we don't have currently,
please fire a issue for feature request.
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.

### License

Expand Down

0 comments on commit b08f3b4

Please sign in to comment.