怎么在vue.js中实现一个仿hover效果

怎么在vue.js中实现一个仿hover效果?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

具体如下:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      list-style: none;
    }
    ul{
      margin:100px ;
    }
    li{
      width: 50px;
      height: 50px;
      border: 1px solid;
      float: left;
      text-align: center;
      line-height: 50px ;
    }
    .act{
      background: red;
    }
  </style>
</head>
<body>
<ul id="app">
  <li @click="fun(x)" v-for="x in num" :class="index===x?'act':''">{{x}}</li>
</ul>
</body>
<script src="https://cdn.bootcss.com/vue/2.4.4/vue.min.js"></script>
<script>
  const app=new Vue({
    el:"#app",
    data:{
      num:10,
      index:1,
    },
    methods:{
      fun(x){
        this.index=x
      }
    }
  })
</script>
</html>

关于怎么在vue.js中实现一个仿hover效果问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注行业资讯频道了解更多相关知识。