uniapp for循环点击事件传参报错:Undefined

for循环点击事件传参Undefined

// 报错写法:
<view v-for="item in navGroup" :key="item.index">
		<view class="nav-group-item" @click="navHandle(item.path)">
			
		<view class="bottom" v-if="!item.last"></view>
</view>
// 改为如下写法 v-for="(item,index) in navGroup" 
<view v-for="(item,index) in navGroup" :key="index">
		<view class="nav-group-item" @click="navHandle(item.path)">
			
		<view class="bottom" v-if="!item.last"></view>
</view>
// 指定this写法  @click="()=>navHandle(item.path)"
<view v-for="item in navGroup" :key="item.index">
		<view class="nav-group-item" @click="()=>navHandle(item.path)">
			
		<view class="bottom" v-if="!item.last"></view>
</view>

报错原因可能是循环的点击事件没有正确绑定到所属下的Item导致没有正确获取到参数

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
uniapp中,`beforeRouteLeave` 是Vue-router提供的生命周期函数,可以在页面跳转前执行一些操作。如果你在使用 `beforeRouteLeave` 时发现它不生效,可能是以下几种原因: 1. 页面没有使用Vue-router进行路由管理 `beforeRouteLeave` 是Vue-router提供的生命周期函数,如果你的页面没有使用Vue-router进行路由管理,那么这个函数是不会生效的。因此,你需要确保你的页面使用了Vue-router进行路由管理。 2. 页面的路由配置中没有设置beforeRouteLeave 如果你的页面使用了Vue-router进行路由管理,那么你需要在路由配置中设置 `beforeRouteLeave` 函数才能使它生效。 ``` const router = new VueRouter({ routes: [ { path: '/home', component: Home, beforeRouteLeave(to, from, next) { // 在这里可以执行一些操作,例如询问用户是否确定离开页面等 next() } } ] }) ``` 3. beforeRouteLeave 中的 next 函数未被调用 在 `beforeRouteLeave` 中,必须调用 `next()` 函数才能正常进行页面跳转。如果你在 `beforeRouteLeave` 中没有调用 `next()` 函数,那么页面跳转将被阻止,导致 `beforeRouteLeave` 不生效。 ``` beforeRouteLeave(to, from, next) { // 在这里可以执行一些操作,例如询问用户是否确定离开页面等 next() } ``` 如果你确认以上几点都已经检查过了,但 `beforeRouteLeave` 依然不生效,可能是其他原因导致的,你可以在开发者工具中打开调试模式,查看控制台是否有相关的信息,以便更好地排查问题。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值