Skip to content

Instantly share code, notes, and snippets.

@cristijora
Last active July 11, 2019 19:06
Show Gist options
  • Save cristijora/ce9353c4bf267c2b4c11c528373f7165 to your computer and use it in GitHub Desktop.
Save cristijora/ce9353c4bf267c2b4c11c528373f7165 to your computer and use it in GitHub Desktop.
<template>
<div>
<input placeholder="Email" type="email" v-model="form.email"/>
<input placeholder="Name" v-model="form.name"/>
<button @click="onSave">Save</button>
<button @click="onCancel">Save</button>
</div>
</template>
<script>
export default {
props: {
user: {
type: Object,
default: () => ({})
}
},
data() {
return {
form: {}
}
},
methods: {
onSave() {
this.$emit('submit', this.form)
},
onCancel() {
this.form = {...this.user}
this.$emit('cancel')
}
}
watch: {
user: {
immediate: true,
handler: function(userFromProps){
if(userFromProps){
this.form = {
...this.form,
...userFromProps
}
}
}
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment