Skip to content

Instantly share code, notes, and snippets.

@MehdiKhoshnevisz
Created September 3, 2022 08:16
Show Gist options
  • Save MehdiKhoshnevisz/fc56ff02e6dfe8d003a2c02e10cfea96 to your computer and use it in GitHub Desktop.
Save MehdiKhoshnevisz/fc56ff02e6dfe8d003a2c02e10cfea96 to your computer and use it in GitHub Desktop.
This is a vue mixin that is used to reduce boilerplate.
/*
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