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>Documen</title>
</head>

<body>
    <div id="app">
        <!-- 图片 -->
        <img v-bind:src="imgArr[index]" alt="">
        <!-- 左箭头 -->
        <button v-on:click="prev" v-show="index!=0">上一张</button>
        <!-- 右箭头 -->
        <button v-on:click="next" v-show="index<imgArr.length-1">下一张</button>
    </div>
    <!-- 开发环境版本,包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> <br>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                message: 'Hello Vue!',
                imgArr: ["https://cjunn.gitee.io/blog_theme_atum/style1/img/ing/ingbc.webp",
                        "https://pic.cnblogs.com/avatar/2210235/20201122215811.png"],
                index:0
            },
            methods:{
                prev:function(){
                    this.index--;
                },
                next:function(){
                    this.index++;
                }
            }
        })
    </script>
</body>

</html>

posted @ 2021-06-21 22:15  一个经常掉线的人  阅读(79)  评论(0)    收藏  举报