vue导航条选中项样式

html:

<div id="app">
  <div class="collection">
    <a href="#!" v-for="gameName in gameNames"
       @click="selected(gameName)"
       :class="{active: activeName == gameName}">{{gameName}}</a>
  </div>
</div>

 

javascript:

new Vue({
  el: "#app",
  data: {
    gameNames: ['魔兽世界', '暗黑破坏神Ⅲ', '星际争霸Ⅱ', '炉石传说', '风暴英雄',
      '守望先锋'
    ],
    activeName: ''
  },
  methods: {
    selected: function(gameName) {
      this.activeName = gameName
    }
  }
})

  

posted @ 2018-01-02 15:15  code-luyf  阅读(1295)  评论(0编辑  收藏  举报