Vue中为什么会出现$index is not defined的提示错误?

2026-04-03 01:112阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计355个文字,预计阅读时间需要2分钟。

Vue中为什么会出现$index is not defined的提示错误?

今天学习Vue中遇到了一个错误信息:$index is not defined,原因是我在HTML中写了一个for循环。下面是解决方案:

原本的代码是:v-for=person in items v-on:click=deletePerson($index)

解决方案:v-for=(person, index) in items v-on:click=deletePerson(index)

Vue中为什么会出现$index is not defined的提示错误?

今天学习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错误的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

本文共计355个文字,预计阅读时间需要2分钟。

Vue中为什么会出现$index is not defined的提示错误?

今天学习Vue中遇到了一个错误信息:$index is not defined,原因是我在HTML中写了一个for循环。下面是解决方案:

原本的代码是:v-for=person in items v-on:click=deletePerson($index)

解决方案:v-for=(person, index) in items v-on:click=deletePerson(index)

Vue中为什么会出现$index is not defined的提示错误?

今天学习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错误的解决方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。