I am new to VueJS. I am trying to create a form with a simple Save and Cancel function. When binding the model to the fields, they are updated immediately as the inputs change, but I do not want this to be a hard binding. Instead, I want to save and send when the "Save" button is clicked, and revert the changes when the "Cancel" button is clicked.
What is the proposed Vue method for this?
It would also be ideal if we can show the serverβs save status and indicate it in the form if the feed failed. If you know any examples or patterns that would be extremely helpful. Thanks!
See JSFiddle
<template> <div id="app"> <div> First Name: <input type="text" v-model="user.firstName" :disabled="!isEditing" :class="{view: !isEditing}"> </div><div> Last Name: <input type="text" v-model="user.lastName" :disabled="!isEditing" :class="{view: !isEditing}"> </div> <button @click="isEditing = !isEditing"> {{ isEditing ? 'Save' : 'Edit' }} </button> <button v-if="isEditing" @click="isEditing = false">Cancel</button> </div> </template> <script> var app = new Vue({ el: '#app', data: { isEditing: false, user: { firstName: 'John', lastName: 'Smith' } } }) </script> <style> .view { border-color: transparent; background-color: initial; color: initial } </style>
source share