Question 16
Consider the below Vue.js application.
<template> <div> <input v-model="name" placeholder="Enter name"> <input v-model="email" placeholder="Enter email"> <button @click="submitForm">Submit</button> </div></template>
<script>export default { data() { return { name: '', email: '' }; }, mounted() { if (localStorage.getItem('formData')) { const savedData = JSON.parse(localStorage.getItem('formData')); this.name = savedData.name; this.email = savedData.email; } }, watch: { name(newVal) { localStorage.setItem('formData', JSON.stringify({ name: newVal, email:localStorage.email })); }, email(newVal) { localStorage.setItem('formData', JSON.stringify({ name: localStorage.name,email: newVal })); } }, methods: { submitForm() { localStorage.removeItem('formData'); this.name = ''; this.email = ''; } }};</script>What will happen if the user submits the form and reloads the page?
The form data will persist in the input fields even after submission and page reload.
The form data will be cleared after submission, and no data will appear after a page reload.
The form data will appear in the inputs after submission and page reload, but only until the user starts typing again.
The page will go blank.