温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用Vue实现点击显示不同图片的效果

发布时间:2021-04-02 10:56:22 来源:亿速云 阅读:775 作者:小新 栏目:web开发

这篇文章主要介绍如何使用Vue实现点击显示不同图片的效果,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

使用Vue中的以下知识点来显示效果

①:v-for:循环遍历数据
②:v-bind:class={ }:绑定样式
③:v-on:click(简写@click):点击事件
④:v-if:判断

<!DOCTYPE html>
<html>
<head>
 <title>点击显示相对应的图片</title>
 <style type="text/css">
 *{
 margin: 0;
 padding: 0;
 list-style: none;
 }
 .myul{
 display: flex;
 }
 .myul li{
 border: 1px solid orange;
 height: 150px;
 width: 150px;
 flex-direction: row;
 text-align: center;
 line-height: 150px;
 }
 .content{
 border: 1px solid grey;
 height: 350px;
 width: 600px;
 }
 .content img{
 height: 350px;
 width: 600px;
 }
 .active{
 background: #3A9ffb;
 color: white;
 }
 </style>
</head>
<body>
 <div class="app">
 <div class="title">
 <ul class="myul">
 <li v-for="(item,index) in mess" v-bind:class="{ 'active': status === index}" v-on:click="changeImg(index)">
  {{item.content}}
 </li>
 </ul>
 </div>
 <div class="content">
 <img src="img/1.jpg" v-if="status === 0">
 <img src="img/2.jpg" v-if="status === 1">
 <img src="img/84.jpg" v-if="status === 2">
 <img src="img/85.jpg" v-if="status === 3">
 </div>
 </div>
</body>
</html>
<script src="https://cdn.bootcss.com/vue/2.5.20/vue.js"></script>
<script type="text/javascript">
 new Vue({
 el:".app",
 data:{
 status:0, //状态显示
 mess:[
 {id:0,content:"点击显示图片一"},
 {id:1,content:"点击显示图片二"},
 {id:2,content:"点击显示图片三"},
 {id:3,content:"点击显示图片四"}
 ]
 },
 methods:{
 changeImg:function(index){
 this.status=index;
 }
 }
 })
</script>

以上是“如何使用Vue实现点击显示不同图片的效果”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue
AI