天天看點

vue 中$index $key 已經移除了

之前可以這樣:

1

2

3

4

5

6

<

ul

id="example">

<

li

v-for="item in items">

{{$index}}

{{$key}}

</

li

>

</

ul

>

現在已經移除,如果還用的話就會報錯:Uncaught ReferenceError: $index is not defined;

現在這樣寫:

1

2

3

4

5

6

<ul id=

"example"

>

<li v-

for

=

"(item,index) in items"

>

{{item}}

{{index}}

</li>

</ul>

第一個參數是值,第二個參數是索引;目的是為了保持和原生的一緻;

源碼

<ul class="supports" v-if="seller.supports">
              <li class="supports_item" v-for="(item,index) in seller.supports" >
                <img class="icon" :src="seller.avatar" alt="" width="12" height="12"></img>
                <span class="text">{{seller.supports[index].description}}</span>
              </li>
            </ul>
           
vue