[Vuejs]-Vue JS Custom directive data binding

0👍

The issue is with the this.set(/* ... */) line. this.set doesn’t work the same as Vue.set or vm.$set.

this.set attempts to set the path that you passed to the directive: v-my-directive="a.b.c". So running this.set('foo') will attempt to set $vm.a.b.c to 'foo'.

What you want to do is this:

(ES6)

this.params.errors.splice(0, this.params.errors.length, ...response.data)

(Vanilla JS)

this.params.errors.splice.apply(this.params.errors, [0,this.params.errors.length].concat(response.data))

That will update whatever Object is tied to the errors param on the DOM Node. Make sure that you do v-bind:errors="formErrors.security" or :errors="formErrors.security".

Leave a comment