猿问

vuejs2.0 的v-for取消了$index,现在我该如何替换获取索引额?

问题如题,原来vue1.x可以如下书写:


<el-carousel-item v-for="(item, key, index) in picList" :key="index" >

                <el-button id="carouselBtn" type="text" v-on:click="openDownLoad($index)" >

                    <img :src="item.img" :alt="item.altstring" class="img-responsive">

                </el-button>

 </el-carousel-item>

因为在vue2.x中$index被废弃了,那如果使用vue2.x,我该如何获得当时的index?


直接写index 点击后 为 undefined


求解?


温温酱
浏览 387回答 1
1回答

繁星淼淼

<el-carousel-item v-for="(item,index) in picList" >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <el-button id="carouselBtn" type="text" v-on:click="openDownLoad(index)" >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <img :src="item.img" :alt="item.altstring" class="img-responsive">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </el-button>&nbsp;</el-carousel-item>&nbsp;&nbsp;methods:{&nbsp; &nbsp; &nbsp;fun () {&nbsp; &nbsp; &nbsp; &nbsp; openDownLoad (index) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(index)&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp;}&nbsp;}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答