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 v-bind:class='{ ’navActive’: scrollFlag }'>
<img src='http://www.cgvv.com.cn/bcjs/@/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錯誤的解決方式就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。
相關文章:
1. docker compose idea CreateProcess error=2 系統找不到指定的文件的問題2. 將properties文件的配置設置為整個Web應用的全局變量實現方法3. 一文秒懂idea的git插件跟翻譯插件4. python爬蟲利用代理池更換IP的方法步驟5. JS中的常見數組遍歷案例詳解(forEach, map, filter, sort, reduce, every)6. Vue+express+Socket實現聊天功能7. 在Vue 中獲取下拉框的文本及選項值操作8. Python語言規范之Pylint的詳細用法9. SpringBoot集成SSM、Dubbo、Redis、JSP的案例小結及思路講解10. python中pandas.read_csv()函數的深入講解
