[Vuejs]-Turn a prop into a data attribute in vuejs 2

1👍

pass an object as the prop:

people = {
  list: [{'name': 'Kevin'}, {'name':'Bert'}, {'name': 'Timmy'}]
}

<House :_people="people"></House>

and then

props: ['_people'],
methods: {
  addMark() {
    this._people.list.push({
      name: 'Mark'
    })
  }
}

1👍

You can use computed property:

export default {
    props: ['_people'],
    data() {
       return {
            added: false
       }
    },
    computed: {
        people() {
            var _arr = this._people.slice();

            return this.added ? _arr : _arr.push({ name: 'Mark' });
        }
    },
    methods: {
        addMark: function(){
            this.added = true
        }
    },
}

Leave a comment