a vue directive of text selection
npm install vue-text-selectionSelection` and `Range` API, It can get the innerText of the selected range.Installation
#### NPM
`
npm install vue-selectable --save
`
#### Direct `` Include`html
`Usage
#### NPM
`js
import selection from 'vue-text-selection';// Register a global custom directive called v-selection
Vue.directive('selection', selection);
// Register the directive locally instead
new Vue({
el: '#app',
directives: { selection },
methods:{
getSelection: function(fixStr, allStr){
// fixStr - the string that fix the boudary
of the dom use the directive of the selection
// allStr - the string of the selection
}
}
});
`
#### Direct `` Include
`js
new Vue({
el: '#app',
directives: {
selection: selection.default
},
methods:{
getSelection: function(fixStr, allStr){
// fixStr - the string that fix the boudary
of the dom use the directive of the selection
// allStr - the string of the selection
}
}
});
`
#### HTML
`html
Text here!
`
Option
`v-selection` requires one mandatory parameter - directive parameter - object with one function, `getSelection`, to get the fixStr ( the string that fix the boudary of the dom use the directive of the selection ) and the allStr ( the string of the selection ).`v-selection` has an optional modifiers, `fix``, to auto limit the selection in the boundary of the dom use the directive.You can find the example in examples directory. Examples for v2 were tested against version 2.5.9.