Last active
July 11, 2019 19:06
-
-
Save cristijora/ce9353c4bf267c2b4c11c528373f7165 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
<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