Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Coffcer/vue-plain

Get plain object from vue getter/setter object.
https://github.com/Coffcer/vue-plain

Last synced: 4 months ago
JSON representation

Get plain object from vue getter/setter object.

Awesome Lists containing this project

README

        

# vue-plain

Get plain object from vue getter/setter object.

## Install

- #### NPM

npm install --save `vue-plain`

- #### CommonJS

``` js
var plain = require('vue-plain')
Vue.use(plain);
```

- #### `` Include

include `vue-plain.js` after `Vue.js`.

## Usage

``` js
let vm = new Vue({
data: {
a: {
a1: 2,
fn: function(){}
},
c: [1, 2, 3]
}
});

console.log( Vue.plain(vm.a) );
// { a: { a1: 2 } }
// The function will be lose, but in general, you should not add function in Vue data

console.log( Vue.plain(vm.c) );
// [1, 2, 3]
```

with prop.coerce (in [email protected] ~ [email protected], coerce() has a bug, so you can't do this in these versions)

``` js
childComponent = {
props: {
obj: {
type: Object, // or Array
coerce (value) {
return Vue.plain(value);
}
}
},
created () {
// this change does not affect parentComponent.obj
this.obj.a = 1;
}
}
```