Vue.js implements image switching function

Vue.js implements image switching function

This article shares the specific code of Vue.js to implement the image switching function for your reference. The specific content is as follows

The functions are as follows

The file directory is as follows. To implement this function, you only need to modify the storage location of the picture.

The code is as follows

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title></title>
  <script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
 </head>
 <style type="text/css">
  div {
   margin: 0 auto;
   width:200px;
   height: 300px;
   border: 1px solid aqua;
  }
  img {
   margin: 0 auto;
   width: 200px;
   height: 250px;
   border: 1px solid aqua;
  }
  
 
 </style>
 <body>
  <div id="app">
   <img :src="imgSrc[index]" >
   <button type="button" @click="prephoto()">Previous photo</button>
   <button type="button" @click="nextphoto()">Next photo</button>
  </div>
  <script type="text/javascript">
   var app = new Vue({
    el:"#app",
    data:{
             imgSrc:["./img/1.jpg","./img/2.jpg"],
    index:1
    },
    methods:{
     prephoto:function(){
      this.index--;
      if(this.index===-1)
      {
       this.index=this.imgSrc.length-1;
      }
      console.log(this.index)
     },
     nextphoto:function(){
      this.index++;
      if(this.index===this.imgSrc.length){
       this.index=0;
      }
      console.log(this.index)
     }
    }
   })
  </script>
 </body>
</html>

Suitable for beginners.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vue realizes picture switching effect
  • Vue+js click arrow to switch pictures
  • Detailed explanation of the use of Vue card-style click-to-switch image component
  • Vue implements simple image switching effect
  • Vue implements button switching picture
  • Vue uses swiper to switch pictures by sliding left and right
  • Vue implements switching function between base64 encoded images
  • Vue custom js picture fragment carousel switching effect implementation code

<<:  Automatically install the Linux system based on cobbler

>>:  Explanation of the usage scenarios of sql and various nosql databases

Recommend

Mybatis paging plug-in pageHelper detailed explanation and simple example

Mybatis paging plug-in pageHelper detailed explan...

The process of installing SVN on Ubuntu 16.04.5LTS

This article briefly introduces the process of se...

Analysis of the difference between Mysql InnoDB and MyISAM

MySQL supports many types of tables (i.e. storage...

Use image to submit the form instead of using button to submit the form

Copy code The code is as follows: <form method...

Detailed explanation of MySQL DEFINER usage

Table of contents Preface: 1.Brief introduction t...

jQuery implements ad display and hide animation

We often see ads appear after a few seconds and t...

Implementation steps of encapsulating components based on React

Table of contents Preface How does antd encapsula...

Exploring the practical value of the CSS property *-gradient

Let me first introduce an interesting property - ...

Abbreviation of HTML DOCTYPE

If your DOCTYPE is as follows: Copy code The code ...

Parameters to make iframe transparent

<iframe src="./ads_top_tian.html" all...

Node+express to achieve paging effect

This article shares the specific code of node+exp...

Use of Linux crontab command

1. Command Introduction The contab (cron table) c...

Summary of the use of html meta tags (recommended)

Meta tag function The META tag is a key tag in th...

How to automatically import Vue components on demand

Table of contents Global Registration Partial Reg...