zoukankan      html  css  js  c++  java
  • vue简单的导航栏

    
    
    <style>
      img{
        display:block;
        margin:0 auto;
        width:500px;
        height:500px;
      }
        #app li{
        list-style: none;
      }
    
    </style>
    <body>
        <div id="app">
    
           <img :src="img" @click="autoCg()"> <!--显示一张图片,并给图片添加点击事件-->
              <ul>
                        <li v-for="(item,index) in json"></li>
              </ul>
              <button @click="prev">上一张</button>
              <button @click="next">下一张</button>
       </div>
    </body>
    <script>
    
    
           new Vue({
               el:'#app',
               data:{
                   img:'./images/cao.jpg',
                   json:[
                       "./images/cao.jpg",
                       "./images/hua.jpg",
                       "./images/ning.jpg",
                       "./images/shu.jpg",
                   ],
                   index:0
               },
               methods:{
                   next(){
                       this.img = this.json[this.index++];
                       if(this.index > 3){
                           this.index = 0; //当超过图片数量,返回第一张图片
                       }
                   },
                   prev(){
                       this.img = this.json[this.index--];
                       if(this.index < 0){
                           this.index = 3;
                       }
                       //当index值<0时,返回最后一张图片
                   },
                   //点击首张图片触发函数功能
                   autoCg(){
                       let self = this;
                       //定时器,每2秒换一张图片
                       setInterval(function(){
                           self.img = self.json [self.index++];
                           if(self.index > 3){
                               self.index = 0;
                           }
                       },2000);
                   }
    
               },
    
    
    
       })
    </script>


  • 相关阅读:
    MySQL重置密码
    linux下自动备份脚本并上传到ftp服务器
    nginx配置
    WIFI防蹭网
    无线路由知识
    009汇编环境搭建
    008 计算机不会加法
    007计算机不会做加法
    006源码反码补码
    005有符号数和无符号数
  • 原文地址:https://www.cnblogs.com/hujun-2018/p/10023721.html
Copyright © 2011-2022 走看看