vue使用rules 國(guó)際化時(shí) form表單驗(yàn)證信息不能及時(shí)更新

實(shí)例問(wèn)題 比如打開(kāi)新建頁(yè)面時(shí) 為英文


image.png

此時(shí)出去 切換成中文后 表單驗(yàn)證信息為改變?yōu)橹形?/p>

image.png

這其實(shí)是變量數(shù)據(jù)未能再次綁定上 解決方法 放到computed 計(jì)算屬性里面
這里rules 對(duì)應(yīng)form中 :rules=“rules ” 的對(duì)象 里面的參數(shù) 對(duì)應(yīng)form中 每個(gè)單元的prop屬性


image.png
computed:{
      rules(){
          return{
            address:[
              { required:true, message: this.$t('location.validate.address'), trigger:'blur'}
            ],
            lat:[
              { required:true, message: this.$t('location.validate.lat'), trigger:'blur'},
              {
                pattern: /^[\-\+]?((0|([1-8]\d?))(\.\d{1,6})?|90(\.0{1,6})?)$/, 
                message: this.$t('location.validate.latfmt')
              }
            ],
            lng:[
              { required:true, message: this.$t('location.validate.lng'), trigger:'blur'},
              {
                pattern: /^[\-\+]?(0(\.\d{1,6})?|([1-9](\d)?)(\.\d{1,6})?|1[0-7]\d{1}(\.\d{1,6})?|180\.0{1,6})$/, 
                message: this.$t('location.validate.lngfmt') 
              }
            ],
            regionname:[
              { required:true, message: this.$t('location.validate.regionname') , trigger:'blur'},
            ]
          }
      }
    },

到此解決


image.png

當(dāng)然 你若是寫(xiě)的行內(nèi)告警規(guī)則 如:


image.png

則是自動(dòng)雙向綁定的

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容