Created
September 3, 2022 08:16
-
-
Save MehdiKhoshnevisz/fc56ff02e6dfe8d003a2c02e10cfea96 to your computer and use it in GitHub Desktop.
This is a vue mixin that is used to reduce boilerplate.
This file contains 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
/* | |
This mixin is used to reduce boilerplate | |
Vue v-model is actual shortcut for v-bind="value" and v-on:input | |
Add this mixin in your component and add <v-model='model'> on your input component | |
*/ | |
export default { | |
props: { | |
value: [String, Object, Boolean, Array, Number], | |
}, | |
methods: { | |
emit(val, type = 'change') { | |
this.$emit(type, val) | |
}, | |
}, | |
computed: { | |
model: { | |
get() { | |
return this.value | |
}, | |
set(value) { | |
this.$emit('input', value) | |
}, | |
}, | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment