【发布时间】:2021-02-28 23:07:36
【问题描述】:
我不明白为什么这个指令在模型更新时没有更新应用元素的禁用状态。
谁能看到我做错了什么?
import { DirectiveOptions } from 'vue';
const disableAllDirective: DirectiveOptions = {
componentUpdated: function (el, binding) {
if (!binding.value) return;
const tags = ["input", "button", "textarea", "select"];
tags.forEach(tagName => {
const nodes = el.getElementsByTagName(tagName);
for (let i = 0; i < nodes.length; i++) {
(<HTMLInputElement>nodes[i]).disabled = true;
(<HTMLInputElement>nodes[i]).tabIndex = -1;
}
});
}
};
export default disableAllDirective;
我正在应用这样的指令:
<div class="col-5" v-disableAll="!selectedBusinessId">
<div class="form-row">
<label class="col-1 pt-1 col-form-label-sm">Search:</label>
<div class="col-6 form-inline">
<input id="txtClientSearch" @change="searchClients" v-model.lazy="clientSearchTerm" placeholder="Facility / Client Name" class="form-control" autocomplete="off" />
<input id="txtClientIdSearch" @change="searchClients" v-model.lazy="clientIdSearch" v-validate="'between:1,32767'" data-vv-as="Customer Number" placeholder="Number" class="form-control number-without-spinner" autocomplete="off" type="number" />
<button v-on:click="searchClients" class="btn btn-outline-secondary btn-sm form-control-xsm"><i class="fa fa-search"></i></button>
<button v-on:click="onClearSearchClick" class="btn btn-outline-primary btn-sm form-control-xsm"><i class="fa fa-times"></i></button>
</div>
<div class="col-auto form-check form-check-inline checkbox checkbox-primary">
<input v-model="showInactiveClients" v-on:change="searchClients" id="chkInactive" class="form-check-input" type="checkbox" value="inActive">
<label class="form-check-label no-padding" for="chkInactive">Show Inactive</label>
</div>
</div>
</div>
【问题讨论】: