Last active
May 27, 2018 03:07
-
-
Save dannyrb/59ebb502b93bdcba940c1614cb20c771 to your computer and use it in GitHub Desktop.
Example: Basic v-cache configuration
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
<template><!-- Business as usual --></template> | |
<script> | |
export default { | |
name: 'BasicForm', | |
data() { | |
return { | |
// Default setup uses 'form' object in | |
// data as cache target and restore cache target | |
form: { | |
name: '', | |
email: '', | |
message: '', | |
termsAccepted: false | |
} | |
} | |
}, | |
watch: { | |
// Watch for changes to all of form's properties | |
// and trigger caching behavior | |
form: { | |
handler: function() { | |
this.$emit("cache", this.form); | |
}, | |
deep: true | |
} | |
}, | |
mounted() { | |
// After this form is rendered, restore its form values | |
// if it has any cached form values | |
this.$emit("restore-cache"); | |
}, | |
methods: { | |
pretendSubmitForm() { | |
this.form = { | |
username: "", | |
email: "", | |
message: "", | |
termsAccepted: false | |
}; | |
// Clear any cached values for this form | |
this.$emit("clear-cache"); | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment