Vue: $vm.$delete('object.key') doesn't work

Created on 1 Aug 2016  ·  3Comments  ·  Source: vuejs/vue

Vue.js version

1.0.26

Reproduction Link

http://jsbin.com/cavadiwosi/1/edit?html,js,console,output

Steps to reproduce

$vm.$delete('object.key')

What is Expected?

$vm.object.key should not exist
$vm.$set('object.key', value) seems to work fine

What is actually happening?

$vm.object.key doesn't change

Most helpful comment

$set and $delete are deprecated in the new version. Use Vue.set and Vue.delete instead.

toggleRow: function(row) {
  key = row.id
  if (this.selectedRows[key]) {
    console.log('deleteRow: ', key)
    Vue.delete(this.selectedRows, key)
  }
  else {
    Vue.set(this.selectedRows, key, row)
  }   
}

All 3 comments

$set and $delete are deprecated in the new version. Use Vue.set and Vue.delete instead.

toggleRow: function(row) {
  key = row.id
  if (this.selectedRows[key]) {
    console.log('deleteRow: ', key)
    Vue.delete(this.selectedRows, key)
  }
  else {
    Vue.set(this.selectedRows, key, row)
  }   
}

Note the API only supports deleting the vm's own keys. Also, prefer Vue.delete.

@kingdaro vm.$set and $vm.delete does not seem to be deprecated in actual version 2.x https://vuejs.org/v2/api/#vm-set :)

Was this page helpful?
0 / 5 - 0 ratings