v-for遍历router-link 实现导航跳转

在这里插入图片描述

<template>
  <div class="box"> 
      联系我们
    <div class="dot_nav">
     <div class="dot"  v-for="(operate,path,index) in navTo.operate" @click="change(index)" :class="{ bgColors:index==current}">
        <router-link :to="{ path: operate.path }">
        {{operate.name}}
      </router-link>
     </div>     
    </div>
  </div>  
</template>

<script>

export default {
   methods: {
    change: function (index) {
      console.log(this); //vue实例
      console.log(index);
      this.current = index;
    },
  },data () {
    return {current: 0,
        navTo:{
            "operate":[
                  {"name":"","path":'/'},
                  {"name":"服务项目","path":'/serviceproject'},
                  {"name":"客户案例","path":'/contactus'},
                  {"name":"新闻资讯","path":'/customercase'},
                  {"name":"联系我们","path":'/news'},
           ]
        }
    }
  }
}
</script>

<style scoped>
.box{
  width: 100%;
  height: 500px;
  background-color: greenyellow;
}
.router-link-exact-active{
  background: #ff5700;
}
</style>

router.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import index from './pages/index.vue'
import contactUs from './pages/contactUs.vue'
import customerCase from './pages/customerCase.vue'
import news from './pages/news.vue'
import serviceProject from './pages/serviceProject.vue'
Vue.use(VueRouter)
    /*如果在一个模块化工程中使用它,必须要通过
     Vue.use() 明确地安装路由功能:

配置路由的路径 path  配置了关联 并 没有生效*/
const routes = [{
            path: '/',
            component: index
        }, {

            path: '/news',
            component: news
        }, {

            path: '/contactus',
            component: contactUs
        }, {

            path: '/customercase',
            component: customerCase
        }, {

            path: '/news',
            component: news
        }, {
            path: '/serviceproject',
            component: serviceProject
        }

    ]
    // 实例化
const router = new VueRouter({
        routes
    })
    //导出
export default router
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值