在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ iview的Form與Modal同時使用時無法設(shè)置FormItem作為Modal

iview的Form與Modal同時使用時無法設(shè)置FormItem作為Modal footer,無法進行表單驗證

寫了個路由管理頁面,點擊添加路由彈出 modal,填寫表單,并進行自動驗證。
但是用<div slot="footer">無法正確渲染按鈕。

代碼:

html片段:

<Modal v-model="addRouteModal" title="添加路由">
        <Form ref="newRouteInModal" :model="newRouteInModal" :rules="routeValidate" label-position="left" :label-width="100">
            <FormItem prop="target" label="IP地址">
                <Input v-model="newRouteInModal.target" :autofocus="true"></Input>
            </FormItem>
            <FormItem prop="genmask" label="子網(wǎng)掩碼">
                <Input v-model="newRouteInModal.genmask"></Input>
            </FormItem>
            <FormItem prop="gateway" label="網(wǎng)關(guān)地址">
                <Input v-model="newRouteInModal.gateway"></Input>
            </FormItem>

            <div slot="footer">
                <FormItem>
                    <Button type="primary" @click="addRouteModalOnOk('newRouteInModal')">添加</Button>
                    <Button type="ghost" @click="handleReset('newRouteInModal')">取消</Button>
                </FormItem>
            </div>

        </Form>
    </Modal>

js片段:

handleReset(name) {
    this.$refs[name].resetFields();
},

addRouteModalOnOk(name) {
    this.$refs[name].validate((valid) => {
        if (valid) {
            this.$Message.success('Success!');
        } else {
            this.$Message.error('Fail!');
        }
    });
},

如果用modal原生按鈕的話會丟失<FormItem>屬性,this.$refs[name].validate就會失效。

有啥辦法能在modal中使用form的表單驗證功能嗎?

回答
編輯回答
墨染殤
    <Modal
      v-model="updataVisible"
      :mask-closable="false"
      :styles="{top: '16%'}"
      width="800"
      @on-visible-change="beforeClose">
      <div slot="header" class="font-16 font-w900">
        {{updataTitle}}
      </div>
      <Form ref="ruleFormValidate" :model="updataObj" :rules="ruleValidate" :label-width="120" label-position="left">
        </FormItem>
        <!--類型-->
        <FormItem label="Rule Type" prop="ruleType" class="width-80">
          <Select size="large" v-model="updataObj.ruleType" placeholder="Please Select Rule Type" clearable filterable>
            <Option v-for="item in controlRuleTypeList" :value="item.ruleType" :key="item.ruleType">{{ item.value }}</Option>
          </Select>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="primary" size="large" @click="submitForm('ruleFormValidate')">Submit</Button>
        <Button type="ghost" size="large" @click="cancleSubmit('ruleFormValidate')" style="margin-left: 8px">Cancle</Button>
      </div>
      <!--提交時加載動畫-->
      <Spin fix v-if="subLoading">
        <Icon type="load-c" size=30 class="demo-spin-icon-load"></Icon>
        <div>Submitting...</div>
      </Spin>
    </Modal>

這樣驗證沒問題
2017年3月16日 09:01