在mounted钩子函数中,调用了getYears()和onClickItem()方法,但是在onClickItem()方法中,使用了参数e,即事件对象,但是mounted钩子函数中并没有传入参数e,所以在点击事件触发时,会报错"TypeError: Cannot read properties of undefined (reading 'currentIndex')"。

解决方法是在mounted钩子函数中调用onClickItem()方法时传入一个默认的事件对象,例如:

mounted() {
   // ...
   this.onClickItem({ currentIndex: 0 });
},

这样就可以避免报错了。

uni-segmented-control current=current values=items clickItem=onClickItem styleType=button activeColor=#4cd964uni-segmented-control			 view class=content			 view v-show=current === 0

原文地址: https://www.cveoy.top/t/topic/hzCf 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录