Last active
December 3, 2020 05:27
-
-
Save zgunz42/706cb28df34a238b9021ea54fbd9144b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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