iview验证input必填

点击按钮 弹出,

 <!-- 点击新增 -->
            <Modal ref="formModal" v-model="modal" width="400" :closable="false" :loading="true" :mask-closable="false" class-name="vertical-center-modal"	@on-ok="mouldSave">
			<Form ref="form" :model="form" :rules="rule" :label-width="120">
				<FormItem label="模具名称:" prop="dieName">
					<Input v-model="form.dieName" autocomplete="off" />
				</FormItem>
				<FormItem label="模腔数:" prop="idNumber">
					<Input v-model="form.idNumber" autocomplete="off" />
				</FormItem>
				<FormItem label="产件周期(秒):" prop="cycle">
					<Input v-model="form.cycle" autocomplete="off" :disabled="form.id!=''"/>
				</FormItem>
				<FormItem label="上传产品图片:" prop="picture">
                              <div class="upload-item">
						<Button type="primary" >上传</Button>
						<input type="file" name="file" @change="upload($event,1)" accept="image/gif,image/jpeg,image/jpg,image/png" />
					</div>
				</FormItem>
			</Form>
		</Modal>

验证input是否必填

 rule:{
       dieName: [
                    {required: true, message: '必填'}
              ],
              idNumber: [
                    {required: true, message: '必填'}
              ],
              cycle: [
                    {required: true, message: '必填'},
              ],
              picture: [
                    {required: true, message: '必填'}
              ],
        },

你可能感兴趣的:(vue.js)