In vue, how to make the list click events in the list looped out by v-for jump to different pages

  <ul>
    <li v-for="(item,key) in list" :key="key">
      <span @click="$router.push()">{{item.name}}</span>
    </li>
  </ul>
  
  list: [{
    name: ""
  }, {
    name: ""
  }, {
    name: ""
  }, {
    name: ""
  }]
  
  
  
  
Mar.02,2021

you can add route fields to your list array, and dynamically get their respective hop routes when you click


give you an official document link: https://router.vuejs.org/zh-c.


<ul>
    <li v-for="(item,key) in list" :key="key">
      <router-link :to=""></router-link>
    </li>
  </ul>

just traverse the corresponding route into the: to of router-link.

Menu