Skip to content

Instantly share code, notes, and snippets.

@zgunz42
Last active December 3, 2020 05:27
Show Gist options
  • Save zgunz42/706cb28df34a238b9021ea54fbd9144b to your computer and use it in GitHub Desktop.
Save zgunz42/706cb28df34a238b9021ea54fbd9144b to your computer and use it in GitHub Desktop.
import { boot } from 'quasar/wrappers';
// NOTE: maunya biar directive ini seperti gabungan dari v-bind dan v-on tapi enggak mau dia
export default boot(({ Vue }) => {
Vue.directive('cform', {
// When the bound element is inserted into the DOM...
bind(el, binding, vNode) {
if (!binding.arg) {
console.warn(`v-cform without argument does not support.`);
}
const key = binding.arg;
const setField = binding.value;
const field = setField(key);
vNode.componentOptions.Ctor.mixin({
mounted() {
Object.entries(field.attrs).map(([key, value]) => {
this.$set(this.$props, key, value);
});
Object.entries(field.listeners).map(([key, val]) => {
if (val instanceof Function) {
console.log(this);
this.$on(key, (...args) => {
val(...args);
Object.entries(field.attrs).map(([key, value]) => {
this.$set(this.$props, key, value);
});
});
}
});
},
});
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment