我有以下代码来检查输入字段是否设置了必需的属性。
computed: {
isRequired: function (input) {
input = document.getElementsByTagName('input');
for (var i = 0; i < input.length; i++) {
return this.input.hasAttribute('required') ? 'test-class' : '';
}
}
}
带有输入组件代码的html模板。
<div :class="isRequired" class="o-pf-required pull-left">*</div>
<div class="col-md-6 col-lg-6" style="padding-right: 0px">
<!--
padding-right: 0px here cancels out padding on the bootstrap
col-lg-12 wrapper keeping the 15px padding of the outer div consistant.
-->
<input :type="type" class="o-pf-input" :class="isCheckBox" :placeholder="placeholder" :name="placeholder" :required="isRequired ? true : false" :value = 'value' @input="value = $event.target.value">
<label :for="placeholder"> {{ placeholder }} </label>
</div>
我想要实现的是将测试类应用于o-pf-required类隐藏星号的元素,但浏览器给出了以下错误: