<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="./node_modules/vue/dist/vue.js" type="text/javascript" charset="utf-8"></script> <script src="./node_modules/element-ui/lib/index.js"></script> <link rel="stylesheet" href="./node_modules/element-ui/lib/theme-chalk/index.css"> <title></title> <style> .active { color: red; background-color: lightslategrey; } ul, li { padding: 0; margin: 0; list-style: none; line-height: 40px; } </style> </head> <body> <div id="app"> <ul> <li v-for="(item,index) in movies" :class="{active:selectIndex==index}" @click="liClick(index)"> {{item}} </li> </ul> </div> <script> const vm = new Vue({ el: "#app", data() { return { movies: ["决战中途岛", "误杀", "叶问4", "唐人街探案3", "终结者:黑暗命运"], selectIndex: 0 } }, methods: { liClick(index) { this.selectIndex = index } }, }) </script> </body> </html>