vue jsx 表單 v-decorator 的錯誤


原來是這樣寫 

<a-form-item
            label='計量單位'
            label-col={formConfig.labelCol}
            wrapper-col={formConfig.wrapperCol}>
            <a-select
              placeholder={'請選擇計量單位'}
              v-decorator={[
                'unit',
                {
                  initialValue: undefined,
                  rules: [{ required: true, message: '請選擇計量單位' }],
                },
              ]}>
              {this.unit.map(x => (<a-select-option value={x.id}>{x.name}</a-select-option>))}
            </a-select>
</a-form-item>

這樣 頁面 會 先 於 傳進來 的 record 賦值 ,報

Warning: You cannot set a form field before rendering a field associated with the value. You can use `getFieldDecorator(id, options)` instead `v-decorator="[id, options]"` to register it before render.
警告:在呈現與該值關聯的字段之前,您無法設置表單字段。 您可以使用`getFieldDecorator(id,options)`代替`v-decorator =“ [id,options]”`在渲染之前進行注冊。

 

這個時候 只需要 去掉 v-decorator =“ [id,options] " 改成 

              <a-form-item
                label='提前到場天數'
                label-col={formConfig.labelCol}
                wrapper-col={formConfig.wrapperCol}
              >
                {
                  this.form.getFieldDecorator('presentDays', {
                    initialValue: null,
                    rules: [
                      { pattern: /^[1-9]\d*$/, message: '請輸入正確數字' },
                      { required: true, message: '請輸入數字' },
                    ],
                  })(
                    <a-input-number
                      style='width:100%'
                      min={0}
                      precision={0}
                      placeholder={'請輸入提前到場天數'}
                    />,
                  )
                }

              </a-form-item>

這樣的寫法就行 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM