iview+vue 踩坑大全

 

 

1.iview確認密碼校驗

這是一個重置密碼的彈窗,iview3的彈窗關閉和校驗會有衝突,我採用了自定義的寫法。html

<Modal v-model="modalPassword" :loading=true :mask-closable="false" @on-cancel="handleReset('resetPassword')"> <div slot="header"> <span>重置密碼</span> </div> <Form :model="resetPassword" ref="resetPassword" :rules="ruleValidate" :label-width="120"> <FormItem label="新密碼" prop="Firstpassword"> <Input v-model="resetPassword.Firstpassword"></Input> </FormItem> <FormItem label="確認密碼" prop="Secondpassword"> <Input v-model="resetPassword.Secondpassword"></Input> </FormItem> </Form> <div slot="footer"> <Button @click="handleReset('resetPassword')">取消</Button> <Button type="primary" @click="passwordOk">肯定重置</Button> </div> </Modal>
data() {
    const pwdCheckValidate = (rule, value, callback) => {
      let vm = this; if (value == '') { return callback(new Error('確認密碼不能爲空')); } else if (value != vm.resetPassword.Firstpassword) { return callback(new Error('兩次密碼不一致')); } else { callback(); } }; return {  resetPassword:{},  ruleValidate:{  Firstpassword: [ { required: true, message: '新密碼不能爲空', trigger: 'blur' }, { type: 'string', pattern: /(?![0-9A-Z]+$)(?![0-9a-z]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/, message: '密碼由8-20位大小寫字母數字組成', trigger: 'blur' } ],  Secondpassword: [ { required: true, trigger: 'blur', validator: pwdCheckValidate }, { type: 'string', pattern: /(?![0-9A-Z]+$)(?![0-9a-z]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,20}$/, message: '密碼由8-20位大小寫字母數字組成', trigger: 'blur' } ] } } }

注意:數據庫

  • form表單的model加冒號,model與ref要保持一致
  • prop是用於表單校驗的,重置表單不加則清除不掉

2.iview重置表單不能用

handleReset(name) {
      let vm = this;
      if (this.$refs[name] !== undefined) { this.$refs[name].resetFields(); } }

加一個if判斷就能夠了api

3.校驗表單不能用或者報錯 "TypeError: Cannot read property 'validate' of undefined"

緣由數組

  • 傳參不對
  • this.$refs[ruleForm].validate() 方式不識別。須要使用: this.$refs.ruleForm.validate();

4.iview多選框複選框

<FormItem label="菜單名稱"> <CheckboxGroup v-model="addRole.list" v-for="(item,index) in menuArr" :key="index"> <Checkbox :label="item.menuName"></Checkbox> </CheckboxGroup> </FormItem>

注意markdown

  • list須要定義爲數組
  • lable加冒號

5.iview的複選框與先後臺交互問題

靜態頁面iview

<checkbox-group v-model="pageItem.stu_batch"> <Checkbox label="1">綜合院校</Checkbox> <Checkbox label="2">提早批招生</Checkbox> <Checkbox label="3">無批次招生</Checkbox> <Checkbox label="4">第一批次招生</Checkbox> <Checkbox label="5">第二批次招生A</Checkbox> <Checkbox label="6">第二批次招生B</Checkbox> <Checkbox label="7">第三批次招生A</Checkbox> <Checkbox label="8">第三批次招生B</Checkbox> </checkbox-group>

//渲染頁面的數據ui

pageItem:{ stu_batch:[],//定義爲數組(官方api爲數組) }

與後臺交互的對象(須要與前面pageItem進行賦值)this

pageItemAddAndUpd: { stu_batch:"",//由於我這邊後臺接收的爲字符串 }

//這裏賦值須要進行判斷(由於若是是返回時空值沒有填數據的話須要進行判斷)spa

if(response.data.datalist[0].stu_batch==""||response.data.datalist[0].stu_batch==null){ this.pageItem.stu_batch = []; }else{ this.pageItem.stu_batch = JSON.parse(response.data.datalist[0].stu_batch); }

//這裏是保存操做code

this.pageItemAddAndUpd.stu_batch = JSON.stringify(this.pageItem.stu_batch)//須要將數組轉化成字符串進行後臺保存

6.iview左邊導航欄太長不能滾動

父元素加個overflow: auto;就能夠了

7.iview兩層彈窗第二個一閃而過

setTimeout(_ => { vm.$Modal.confirm({ title: '登陸信息', content: '數據庫未發現該序列號' }); }, 500);

第二個彈窗加個延遲

8.iview表格按鈕不一樣狀況顯示不同

h('Button', { props: { type: 'error', size: 'small' }, style: { marginRight: '5px', display: (params.row.isValid === 0 && this.type === 'tableRole') ? "inline-block" : "none" }, on: { click: () => { this.addRole.roleId = params.row.roleId; this.dataDelete.push(params.row); this.modalDelete = true; } } }, '刪除')

樣式中display判斷一下

相關文章
相關標籤/搜索