在jQuery中:
就是让第一个选中,其他的不选中!
当点击后当前选中,其他不选中。
有一种绕口令:东边的喇嘛买了西边的喇叭
o((⊙﹏⊙))o
在Vue中快速创建与选中
1.遍历出来, 在click中赋值 遍历出来的mx。
2.class进行决定是否显示,一点击就把对应的mx赋到activeName中
3.此时activeName就和mx一模一样的文本,然后返回一个true能显示当前的了
4.把最后一个瑕疵补上, 让第一个默认选中。就是把activeName放一个数值就行了
<template> <div id="app"> <ul> <li v-for="(mx, key) in list" @click="ck(mx)" :class="[{active: activeName == mx}]"> {{mx}} </li> </ul> </div> </template> <script> export default { data() { return { list: ['网易', '腾讯', '爱奇艺', '优酷', '土豆', '斗鱼'], activeName: '网易' } }, methods: { ck(mx) { this.activeName = mx } } } </script> <style lang="less"> .box { list-style: none; text-align: center; padding: 0; width: 85%; margin: auto; margin-top: 30px; ul { list-style: none; text-align: center; li { padding: 15px; border-radius: 30px; } li.active { color: red; transition: all .8s; background: #000; color: #fff; } } } </style>
知识点补充:
exact-active-class 和 active-class 的区别
router-link 默认情况下的路由是模糊匹配,例如当前路径是 /article/1 那么也会激活 <router-link to="/article">,所以当设置 exact-active-class 以后,这个 router-link 只有在当前路由被全包含匹配时才会被激活 exact-active-class 中的 class,例如:
<router-link to="/article" active-class="router-active"></router-link>
当用户访问 /article/1 时会被激活为:
<a href="#/article" class="router-active" rel="nofollow"></a>
而当使用:
<router-link to="/article" exact-active-class="router-active"></router-link>
当用户访问 /article/1 时,不会激活这个 link 的 class:
<a href="#/article" rel="nofollow"></a>
总结
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]