[Vuejs]-Custom Vue.js AJAX directives onSuccess processing

0👍

Your directive needs multiple values a callback function and data and may add up in future. Assign your directive to object literal.

<form method="POST" action="api/groups" v-ajax="{successCb: customSuccessFunction, errorCb: customErrFunction, data: data}">
</form>

In your directive you can access them as below

Vue.directive('ajax', function (el, binding) {
  console.log(binding.value.successCb.color) // => customSuccessFunction
  console.log(binding.value.errorCb.text)  // => customErrFunction
  console.log(binding.value.data) // => data object
})

Leave a comment