javascript - Bottom component, why does the Vue bound class text not change color? The following code
巴扎黑
巴扎黑 2017-07-05 10:40:18
0
5
1310

I put
data () {

return {
  isActive: 'a'
}

}, If the 'a' in
is replaced with 'b', the published words will change color

<template lang="html">
<p class="footer">

<p class="footer-box">
  <router-link :class="{'active': isActive === 'a'}" @click="select('a')" to="/" class="item">首页</router-link>
  <router-link :class="{'active': isActive === 'b'}" @click="select('b')" to="/create" class="item">发表</router-link>
  <router-link :class="{'active': isActive === 'c'}" @click="select('c')" to="/message" class="item">消息</router-link>
  <router-link :class="{'active': isActive === 'd'}" @click="select('d')" to="/user" class="item">我的</router-link>
</p>

</p>
</template>

<script>
export default {
data () {

return {
  isActive: 'a'
}

},
methods: {

select (value) {
  this.isActive = value
}

}
}
</script>

<style lang="less">
.footer {

position: fixed;
left: 0;
bottom: 0;
height: 50px;
width: 100%;
background-color: #fff;
border-top: 1px solid #bbb;
.footer-box {
  display: flex;
  height: 50px;
  width: 100%;
  line-height: 40px;
  .item {
    flex: 1;
    text-align: center;
  }
}

}
.active {

color: #41B883;

}
</style>

巴扎黑
巴扎黑

reply all(5)
曾经蜡笔没有小新

What you wrote is too complicated. This can be done by writing a linkActiveClass when configuring the route. It is recommended to read the documentation of vue-router.
The configuration can be written in the main.js defined route.
const router = new VueRouter({

linkActiveClass: "active",    //设置点击状态的class
mode: 'hash',
hashbang:true,
routes:routerConfig

})

Then add the .active{color: #41B883;} style to your .vue style

router-link is written like this<router-link to="/" class="item">Homepage</router-link>

習慣沉默

It should be enough to replace it with @click.native. Of course, the method above is better

阿神

Replace the click event with @click.native="select('a')";
When writing this kind of navigation, I usually use this method, v-for
<ul>

       <li v-for="(item,index) in liData" :class="    {active:$route.matched[0].path==item.label}" ><router-link :to="item.label">{{item.name}}</router-link></li>

</ul>
data(){

return {

  liData:[
    {name:"首页",label:"/home"},
    {name:"设计器",label:"/designer"},
    {name:"任务管理",label:"/taskmanger"},
    {name:"节点管理",label:"/node"}
  ]
  },
这里的active的变化就是根据地址栏中变化而变化,这样前进后退都不会有问题
过去多啦不再A梦
    <router-link :to="item.url" active-class="act-bar" tag="li" exact>
     
    </router-link>

You can define the selected style .act-bar{}

淡淡烟草味
<p class="footer-box">
   <router-link to="/">
      首页
   </router-link>
</p>
.router-link-active{
    color: #41B883;
}

Just do this. The color set in .router-link-active is the router-link you are currently clicking on. The style color after activation can also be set to other styles, and then other router-links will be restored to the default. Style

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template