自定义验证表单vue

问题描述 投票:0回答:0

**如何在 Button 组件中创建表单的自定义验证?我需要检查是否所有字段都已完成 - 显示单个组件,如果没有 - 显示自定义警报。我想 if 语句没有写正确......

https://codesandbox.io/s/intelligent-jasper-teh1im?file=/src/components/Button.vue:241-254**

<template>
  <button class="btn" @click="submit">Submit</button>
</template>

<script>
export default {
  methods: {
    submit() {
      if (
        !this.firstName &&
        !this.lastName &&
        !this.paymentAmount &&
        !this.accountNumber
      ) {
        this.$emit("final");
      } else {
        alert("please fill the required fields");
      }
    },
  },
  inject: ["firstName", "lastName", "paymentAmount", "accountNumber"],
};
</script>

<style scoped>
.btn {
  padding: 10px 30px;
}
</style>

javascript vue.js vuex styling emit
© www.soinside.com 2019 - 2024. All rights reserved.