element的form校验提交Error in v-on handler: “ReferenceError: formRef is not defined“

在这里插入图片描述

    <div class="form">
      <el-form
        :model="directorForm"
        :rules="directoRules"
        ref="formRef"
        label-width="130px"
        class="demo-ruleForm"
      >
        <el-form-item label="负责人姓名:" prop="name">
          <el-input
            v-model="directorForm.name"
            style="width:400px"
            placeholder="请填写负责人姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="负责人联系电话:" prop="phone">
          <el-input
            v-model="directorForm.phone"
            style="width:400px"
            placeholder="请填写负责人联系电话"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item style="margin-top:40px">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >确认提交</el-button
          >
        </el-form-item> -->
      </el-form>
      <el-button type="primary" @click="submitForm">确认提交</el-button>
    </div>
    submitForm() {
      // formRef
	//会报错改成this.$refs.formRef.validate((valid) => {}
      this.$refs[formRef].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
会报错改成this.$refs.formRef.validate((valid) => {}
根据引用\[1\]中的解释,问题出现在v-on命令中的isCollect变量没有定义。你在代码中已经在data中定义了isCollect变量,但是在方法中使用实例上的变量时,必须使用this来指向这个变量。所以,你需要在v-on命令中使用this.isCollect来引用isCollect变量,这样问题就可以解决了。 #### 引用[.reference_title] - *1* [Error in v-on handler: “ReferenceError: isShow is not defined](https://blog.csdn.net/m0_50013284/article/details/125717671)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Error in v-on handler: “ReferenceError: state is not defined](https://blog.csdn.net/linduj/article/details/127211351)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Vue.js报错问题解决:[Vue warn]: Error in v-on handler: “ReferenceError: XXX is not defined“.](https://blog.csdn.net/m0_56426418/article/details/130162657)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值