Commit f203b14f9fe4ea37c16f343c69222605ca85a99d

Authored by yanyan
1 parent b50e59f5

form-item watch rules change change rules

Showing 1 changed file with 16 additions and 12 deletions   Show diff stats
src/components/form/form-item.vue
... ... @@ -90,6 +90,9 @@
90 90 },
91 91 validateStatus (val) {
92 92 this.validateState = val;
  93 + },
  94 + rules (val){
  95 + this.setRules();
93 96 }
94 97 },
95 98 inject: ['form'],
... ... @@ -143,6 +146,18 @@
143 146 }
144 147 },
145 148 methods: {
  149 + setRules() {
  150 + let rules = this.getRules();
  151 + if (rules.length) {
  152 + rules.every((rule) => {
  153 + this.isRequired = rule.required;
  154 + });
  155 + this.$off('on-form-blur', this.onFieldBlur);
  156 + this.$off('on-form-change', this.onFieldChange);
  157 + this.$on('on-form-blur', this.onFieldBlur);
  158 + this.$on('on-form-change', this.onFieldChange);
  159 + }
  160 + },
146 161 getRules () {
147 162 let formRules = this.form.rules;
148 163 const selfRules = this.rules;
... ... @@ -229,18 +244,7 @@
229 244 value: this.fieldValue
230 245 });
231 246  
232   - let rules = this.getRules();
233   -
234   - if (rules.length) {
235   - rules.every(rule => {
236   - if (rule.required) {
237   - this.isRequired = true;
238   - return false;
239   - }
240   - });
241   - this.$on('on-form-blur', this.onFieldBlur);
242   - this.$on('on-form-change', this.onFieldChange);
243   - }
  247 + this.setRules();
244 248 }
245 249 },
246 250 beforeDestroy () {
... ...