如下所示:
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>选中效果</title> <script src="../static/js/vue.min.js"></script> <style> ul li.active{ color: green; } </style></head><body><div id="app"> <ul> <li v-for="items in navList" :class="{active:items.isActive}" @click="activeFun(items)"> <a> {{items.text}} </a> </li> </ul></div><script> new Vue({ el: '#app', data: { navList: [ {text: '首页', isActive: true}, {text: '简介', isActive: false}, {text: '活动', isActive: false}, {text: '联系', isActive: false} ] }, methods: { activeFun: function(data){ this.navList.forEach(function(obj){ obj.isActive = false; }); data.isActive = !data.isActive; } } });</script></body></html>
以上这篇vue实现点击选中,其他的不选中方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持武林网。
新闻热点
疑难解答