Лучше использовать класс Dynami c. См. Этот пример:
new Vue({
el: '#app',
data: {
productIdLabel: false
}
})
.js-focused {
background-color: lightblue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id='app'>
<label for="formProductId" class="form-element-title" :class="{'js-focused': productIdLabel == true}">Product ID</label>
<input id="formProductId" @blur="productIdLabel = false" @focus="productIdLabel = true" type="text">
</div>
Используется с вводом компонентов и нескольких форм:
Vue.component("form-label", {
template: `<div>
<label :for="info.id" class="form-element-title" :class="{'js-focused': isFocused == true}">{{info.label}}</label>
<input :id="info.id" @blur="isFocused = false" @focus="isFocused = true" type="text">
</div>`,
props: ["info"],
data: function(){
return {
isFocused: false
}
}
})
new Vue({
el: '#app',
data: {
form: [{
label: "Product Id",
id: "formProductId"
}, {
label: "Another Element",
id: "anoterId"
}, {
label: "Third Element",
id: "thirdId"
}]
}
})
.js-focused {
background-color: lightblue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id='app'>
<form-label v-for='el in form' :info='el'></form-label>
</div>