I am currently building a login for a Vue app. In a tutorial (02/2021) I see that the colleague creates a setup method and imports a Vue reactive object into the component. Just to collect the form data! Can't this just be done with the data method?
HTML / Login Component
<template>
<form action="/action_page.php" method="post">
<div class="container">
<input v-model="data.username" type="text" placeholder="Enter Username" name="username" required />
<input v-model="data.password" type="password" placeholder="Enter Password" name="password" required />
<button type="submit">Login</button>
{{ data }}
</div>
</form>
</template>
1. New variant of databinding? Is that really necessary?
import {reactive} from 'vue';
export default {
name: 'Login',
setup() {
const data = reactive({
email: '',
username: ''
})
return {
data
}
}
}
2. Old and easy variant
export default {
name: 'Login',
data() {
return {
data: {
email: '',
username: ''
},
}
},
}