在用i18n实现中英文切换的时候,出现了在表单中校验不更新的问题,尝试多种方式无果,下面这个方法值得一试。可轻松解决此问题。

data(){ ruleInline: { userName: [ { required: true, message:this.$t("insight.form.AccountEmpty"), trigger: ["change", "blur"] } ], password: [ { required: true, message:this.$t("insight.form.passwordEmpty"), trigger: ["change", "blur"] } ], identify: [{ required: true, message:this.$t("verificationCode"), trigger: "blur" }]
  } }
methods: {
    aaa() {
      this.ruleInline = {
        userName: [
          {
            required: true,
            message: this.$t("insight.form.AccountEmpty"),
            trigger: ["change", "blur"]
          }
        ],
        password: [
          {
            required: true,
            message: this.$t("insight.form.passwordEmpty"),
            trigger: ["change", "blur"]
          }
        ],
        identify: [{ required: true, message: this.$t("verificationCode"), trigger: "blur" }]
      }
    }
}
watch: {
    "$i18n.locale": function () {
      this.aaa();
    }
 },
mounted() {
   this.aaa();
}

 

posted on 2022-11-23 14:14  我爱张苗苗  阅读(885)  评论(0编辑  收藏  举报