当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue中提示$index is not defined错误的解决方式

vue中提示$index is not defined错误的解决方式

2020年09月03日  | 移动技术网IT编程  | 我要评论
今天学习vue中遇到了一个报错信息:$index is not defined,是我写了个for循环在html中,然后是因为版本的问题下面是解决方法:原来的是 v-for="person in ite

今天学习vue中遇到了一个报错信息:$index is not defined,是我写了个for循环在html中,然后是因为版本的问题

下面是解决方法:

原来的是 v-for="person in items"

v-on:click="deleteperson($index)"//这个仅仅适用于1.0版本,不要采坑了同学们

这个在vue1.0版本中式适用的可以直接使用$index,但是在2.0是不适合的

在vue 2.0版本中获取索引我们需要通过 v-for = "(person ,index) in items ", 点击事件我们也不能使用$index,应该使用

v-on:click="deleteperson(index)"

补充知识:vue中滚动页面,改变样式&&导航栏滚动时,样式透明度修改

.vue

<div class="commonheader" v-bind:class="{ 'navactive': scrollflag }">

<img src="@/images/home/icon_jdjr.png" v-bind:class="{ 'scrollflag': scrollflag }">

data

scrollflag:false,

mounted

window.addeventlistener('scroll', this.handlescroll)

methods

handlescroll () {
 let _this=this;
 var scrolltop = window.pageyoffset || document.documentelement.scrolltop || document.body.scrolltop
 // console.log(scrolltop)
 if(scrolltop){
  _this.scrollflag=true
 }else{
  _this.scrollflag=false
 }
}

以上这篇vue中提示$index is not defined错误的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网