vue.js 实现if语句逻辑时表单提交按钮不起作用

6ie5vjzr  于 2023-03-03  发布在  Vue.js
关注(0)|答案(1)|浏览(169)
    • 我试图用一个简单的空字符串输入验证来实现提交按钮逻辑,但是在点击按钮之后,整个窗口都变空了。虽然符合if语句,但需要显示一个块。

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

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

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

jvlzgdj91#

似乎您尚未注册FinalStep组件:
[Vue警告]:无法解析组件:FinalStep如果这是一个本地自定义元素,请确保通过compilerOptions.isCustomElement.at将其从组件解析中排除
当我在App. vue中添加它时,它似乎起作用了:

import Form from "./components/Form.vue";
import FinalStep from "./components/FinalStep.vue";
...
export default {
  name: "App",
  ...
  components: {
    Form,
    ProgressBar,
    FinalStep
  },

相关问题