1. 程式人生 > >關於路由跳轉小方法

關於路由跳轉小方法

html:

<div>
    <ul>
        <li v-for="(item,index) in routeList" :key="index" :class="{ select: selItem==index}" @click="routeSelect(index)">
        {{item}}
        </li>
     </ul>
</div>

js:

data(){
    selItem:0,
    routeList: [
    '首頁',
    'get',
    'post',
    'other',
    'ask',
    'content'
    'note'
    ],
    pathList: [
        '/',
        '/main/get',
        '/main/post',
        '/main/other',
        '/main/ask',
        '/main/content',
        '/main/note',
      ],
},
routeSelect(index) {
    this.selItem = index;
    this.$router.push({ path: this.pathList[index] });
  },