Skip to content

Get plain object from vue getter/setter object.

Notifications You must be signed in to change notification settings

Coffcer/vue-plain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

vue-plain

Get plain object from vue getter/setter object.

Install

  • NPM

    npm install --save vue-plain

  • CommonJS

    var plain = require('vue-plain')
    Vue.use(plain);
  • <script> Include

    include vue-plain.js after Vue.js.

Usage

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)

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;
    }
}

About

Get plain object from vue getter/setter object.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published