Created
October 29, 2019 12:25
-
-
Save anoop-ananthan/ca2dd0b235777ca120742e6537559323 to your computer and use it in GitHub Desktop.
Create v-model in custom component
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
### Create component | |
SampleComponent.js | |
``` | |
<template> | |
<div> | |
Mango Component: | |
<input @input="handleInput($event.target.value)" /> | |
</div> | |
</template> | |
<script> | |
export default { | |
prop: ['value'], | |
methods: { | |
handleInput(e) { | |
this.$emit('input', e) | |
}, | |
}, | |
} | |
</script> | |
``` | |
### Parent Component | |
Consume the component as follows: | |
###### Template | |
``` | |
<sample-component v-model="dataMango"></sample-component> | |
<div>Parent Mango:{{ dataMango }}</div> | |
``` | |
###### Data | |
``` | |
import sampleComponent from '@/components/shared/ProjectWarehouse.vue' | |
. | |
. | |
data:()=>({ | |
dataMango: 'Orange' | |
}) | |
Find the best reference [here](https://paulund.co.uk/use-v-model-on-custom-vue-component) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment