Vue.js 文本字段中的vue检查值

Vue.js 文本字段中的vue检查值,vue.js,vuejs2,Vue.js,Vuejs2,我想检查输入中的值,如果输入中有任何值,我想使用VUE将类sh添加到div中,但我不知道如何。。。请帮帮我 <template> <div class="sh-wrap sh-wrap-input sh-is-active"> <label class="sh-label">First and Last Name</label> <input type="text" class="sh-form-control

我想检查输入中的值,如果输入中有任何值,我想使用VUE将类sh添加到div中,但我不知道如何。。。请帮帮我

<template>
   <div class="sh-wrap sh-wrap-input sh-is-active">
      <label class="sh-label">First and Last Name</label>
      <input type="text" class="sh-form-control sh-input" placeholder="First and Last Name" />
      <span for="email" class="error">Required</span>
   </div>
</template>

名
要求的

要检查值是否存在,可以添加
:value=“inputValue”
并使用

watch: {inputValue: function(value){
"add your class here" 

}}

您可以使用
v-model
将值绑定到输入并动态添加类
:class=“{sh处于活动状态”:name}”
。阅读有关如何绑定类和样式的

newvue({
el:“#示例”,
数据(){
返回{
名称:空
}
}
})
.sh换行输入{
填充:1rem;
边框:1px纯色灰色;
}
.sh处于活动状态{
背景:黄色;
}
.sh标签{
显示:块;
边缘底部:.125rem;
}
.错误{
显示:块;
颜色:红色;
字体大小:12px;
边缘顶部:.125rem;
}

名
要求的

@Dota2Match很高兴它成功了。如果你想要更多的信息,你可以阅读我提到的链接中的文档,我还添加了一个工作示例。请确保您接受了正确的答案。您可能要做的是使用v模型设置输入,然后在该模型上设置一个Vue监视,以更改div的类数组。您可能要做的是使用v模型设置输入,然后在该模型上设置一个Vue监视,以更改div的类数组。