Vue writes a v-for loop on the li tag, writes a @ click event, and clicks and pops up an alert

if a total of 10 li, are looped out, how to write

if only the click events of the first four li take effect.
Mar.15,2021

I think the event entrusts you to tie the event to the ul, click to determine whether it is the first four li


Click on the event to pass a parameter index, determines whether it is alert


based on the parameters.

you can do this:

<ul>
    <li v-for="(item,index) in data" @click="index>3?getData():''"></li>
</ul>

can also do this:

<ul>
    <li v-for="(item,index) in data" @click="getData(index)"></li>
</ul>

getData(index){
    if(index>3}{
        return false;
    }
}
Menu