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.gepszalag.com/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. 怎樣才能用js生成xmldom對象,并且在firefox中也實現xml數據島?2. 基于javaweb+jsp實現企業車輛管理系統3. 利用ajax+php實現商品價格計算4. ASP.Net MVC利用NPOI導入導出Excel的示例代碼5. jstl 字符串處理函數6. JSP動態網頁開發原理詳解7. PHP中為什么使用file_get_contents("php://input")接收微信通知8. .Net core Blazor+自定義日志提供器實現實時日志查看器的原理解析9. IOS蘋果AppStore內購付款的服務器端php驗證方法(使用thinkphp)10. XML CDATA是什么?
