vue中提示$index is not defined错误的解决方式
今天学习Vue中遇到了一个报错信息:$indexisnotdefined,是我写了个for循环在HTML中,然后是因为版本的问题
下面是解决方法:
原来的是v-for="personinitems"
v-on:click="deletePerson($index)"//这个仅仅适用于1.0版本,不要采坑了同学们
这个在Vue1.0版本中式适用的可以直接使用$index,但是在2.0是不适合的
在Vue2.0版本中获取索引我们需要通过v-for="(person,index)initems",点击事件我们也不能使用$index,应该使用
v-on:click="deletePerson(index)"
补充知识:vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改
.vue
data
scrollFlag:false,
mounted
window.addEventListener('scroll',this.handleScroll)
methods
handleScroll(){ let_this=this; varscrollTop=window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop //console.log(scrollTop) if(scrollTop){ _this.scrollFlag=true }else{ _this.scrollFlag=false } }
以上这篇vue中提示$indexisnotdefined错误的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。