Vue.js 2 and v-model in an email signature generator
Today I was studying how to use Vue.js 2 to create a dynamic screen in an email signature generator.
I needed to create a simple way for the user to fill in some data, like name, role, phone and email, and see the signature being assembled automatically on the screen.
At first I thought about doing everything with plain HTML, CSS and JavaScript, handling the fields manually. But I started to realize that, as the screen gained more fields and rules, that could become hard to maintain.
I found it interesting how Vue.js 2 made it easier to bind the form inputs to the signature preview. With v-model, I could update the data in real time without having to write several functions to manipulate the DOM manually.
In the form, I could have a field for the name:
<input v-model="name" placeholder="Digite seu nome">
And in the signature preview, that value could already show up automatically:
<strong>{{ name }}</strong>
In the JavaScript, the data would be centralized in the Vue instance:
new Vue({
el: '#app',
data: {
name: '',
role: '',
email: '',
phone: ''
}
})
My initial impression is that Vue.js 2 helped a lot with small but dynamic screens. For an email signature generator it made sense, because I could create a more interactive experience, where the person filled in the data and already saw the final result being updated in real time.