@jf/vue-prop-sep
v2.0.0
Published
Add `get`, `has`, `remove` and `set` methods to Vue componentes.
Downloads
6
Maintainers
Readme
vue-prop-sep
Add get
, has
, remove
and set
methods to Vue componentes.
Usage
Using .
as separator (by default).
import VuePropSep from 'vue-prop-sep';
import Vue from 'vue';
Vue.use(VuePropSep);
// Vue component
export default {
data()
{
return {
a : {
b : 1
}
}
},
created()
{
console.log(this.get('a.b')); // 1
this.set('a.b', 5);
console.log(this.get('a.b')); // 5
}
}
Changing default separator.
import VuePropSep from 'vue-prop-sep';
import Vue from 'vue';
Vue.use(
VuePropSep,
{
separator : '/'
}
);
// Vue component
export default {
data()
{
return {
a : {
b : 1
}
}
},
created()
{
console.log(this.get('a/b')); // 1
this.set('a/b', 5);
console.log(this.get('a/b')); // 5
}
}