I'm new to vue.js. I want to change the output text to the same string that's in placeholder if input value is empty. Here is my desired code
<div id="form">
<input class="input-f" type="text" placeholder="please enter your first name" v-model="firstName">
<input class="input-l" type="text" placeholder="please enter your last name" v-model="lastName">
<div class="output">
<p class="f">{{firstName}}</p>
<p class="l">{{lastName}}</p>
</div>
vuejs with jquery
(function(window) {
var data = {
firstName: "Stack",
lastName: "Overflow",
}
var vm = new Vue({
el: "#form",
data: data,
watch: {
firstName: function(v) {
if (!v) {
$(".f").text($(".input-f").attr("placeholder"))
}
},
lastName: function(v) {
if (!v) {
$(".l").text($(".input-l").attr("placeholder"))
}
}
}
})
})(window)
Also, if I leave the input box empty, the data won't bind again. Please tell me how can I achieve it? https://jsfiddle.net/je491vas/