Vue实现选项卡点击切换图片

  • Post author:
  • Post category:vue


话不多说直接上代码以及实现图


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选项卡</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <style type="text/css">
        .parts span{
            display:inline-block;
            width:200px;
            height:50px;
            margin-left: -10px;
            border:1px solid #000000;
        }
        .parts{
            margin-left: 50px;
        }


        .block{
            width:200px;
            min-height:200px;
            border:1px solid #ddd;
        }
        .block img{
            width: 1400px;
            height: 800px;
        }

    </style>

</head>

<body>
<div id="app">


        <div class="parts">
            <span @click="fun('A');" >卡1</span>
            <span  @click="fun('B');" >卡2</span>
            <span  @click="fun('C');" >卡3</span>
        </div>

        <div class="block" v-if="block=='A'">
            <img src="img/1.jpg">
        </div>
        <div class="block" v-if="block=='B'">
            <img src="img/2.jpg">
        </div>

        <div class="block" v-if="block=='C'">
            <img src="img/3.jpg">
        </div>



</div>
<script type="text/javascript" src="../js/vue.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            active:'A',
            block:'A'
        },

        methods: {
            fun:function(xz){
                this.active=xz;
                this.block=xz;
            }
        }

    });
</script>
</body>
</html>



版权声明:本文为qq_52986363原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。