[Vue warn]: Invalid handler for event ‘‘xxx‘‘: got undefined的解决方案

1 篇文章 0 订阅

问题描述

vue warn
当在vue.js中使用@click,@blur时报出[Vue warn]: Invalid handler for event “blur”: got undefined的三种可能问题

vue代码写错

methods写成method

HTML

<input type="text" v-model="username" @blur="check_username" name="username" id="user_name">

Vue

method: {
	check_username() {
		console.log(this.username)
	}
}

需将vue中的method改成methods

函数名不一致

HTML

<input type="text" v-model="username" @blur="check_username" name="username" id="user_name">

Vue

methods: {
	check_usename() {
		console.log(this.username)
	}
}

HTML中的@blur所指定的函数名与Vue中的methods里的函数不匹配

函数未在methods内

HTML

<input type="text" v-model="username" @blur="check_username" name="username" id="user_name">

Vue

methods: {
}
check_username() {
	console.log(this.username)
}

如代码所示check_username写在methods外同样也会报错

methods没有匹配到其他函数

HTML

<input type="text" v-model="username" @blur="check_username" name="username" id="user_name">
<input type="text" v-model="password" @blur="check_password" name="password" id="pwd">

Vue

methods: {
	check_username() {
		console.log(this.username)
	}
}

由于在methods中并未含有check_password所以同样也会报错,但check_username依旧能正常运行(因为仅涉及控制台)但一旦涉及到修改网页元素,则无法正常渲染页面,同样这样子代码还会如下错误[Vue warn]: Property or method "check_password is not defind on the instance but referenced during render"你可以根据错误代码来识别你哪个函数还未填写或写错。
error_check_password

正确代码

HTML

<input type="text" v-model="username" @blur="check_username" name="username" id="user_name">
<input type="text" v-model="password" @blur="check_password" name="password" id="pwd">

Vue

methods: {
	check_username() {
		console.log(this.username)
	},
	check_password() {
		console.log(this.password)
	}
}
  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值