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 } } })
原文地址:https://www.cnblogs.com/luyuefeng/p/8177328.html
时间: 2024-11-04 00:06:09