Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/Coffcer/vue-plain
- Owner: Coffcer
- Created: 2016-03-26T10:28:28.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-05T06:16:41.000Z (almost 9 years ago)
- Last Synced: 2024-09-19T01:52:30.743Z (5 months ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-vue-cn - vue-plain ★1
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 dataconsole.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;
}
}
```