Vue implements button switching picture

Vue implements button switching picture

This article example shares the specific code of Vue to realize button switching pictures for your reference. The specific content is as follows

Tab

Implementation steps

1. Realize static UI effects

Implementing tag structure and style in a traditional way

2. Reconstruct UI effects based on data

Refactor the static structure and style into a Vue template syntax-based form to handle event binding and js control logic

Set the basic style

{
 overflow: hidden;
 padding: 0;
 margin: 0;
 }

 .tab ul li {
 box-sizing: border-box;
 padding: 0;
 float: left;
 width: 100px;
 height: 45px;
 line-height: 45px;
 list-style: none;
 text-align: center;
 border-top: 1px solid #ccc;
 border-right: 1px solid #ccc;
 cursor: pointer;
 }

 .tab ul li.active {
 background-color: orange;
 }

 .tab ul li:first-child {
 border-left: 1px solid blue;
 }

 .tab div {
 width: 500px;
 height: 300px;
 display: none;
 text-align: center;
 font-size: 30px;
 line-height: 300px;
 border: 1px solid blue;
 border-top: 0px;
 }

 .tab div.current {
 display: block;
}

Implementing static layout

<div id="app">
 <button v-on:click="handla">Switch forward</button>
 <button v-on:click="handlc">One-way cycle switch</button>
 <button v-on:click="handle">Switch back</button>

 <div class="tab">
 <ul>
 <li :class="currentIndex==index?'active':''" :key="item.id" v-for="(item,index) in list">{{item.title}}
 </li>
 </ul>
 <div :class="currentIndex==index?'current':''" :key="item.id" v-for="(item,index) in list">
 <img :src="item.path">
 </div>
 </div>

</div>

Implement specific functions

<script type="text/javascript" src="../js/vue.js"></script>
 <script type="text/javascript">
 /* */
 var vm = new Vue({
 el: '#app',
 data: {
 currentIndex: 0,
 list: [{
  id: 1,
  title: 'apple',
  path: 'img/apple.png'
 }, {
  id: 2,
  title: 'orange',
  path: 'img/orange.png'
 }, {
  id: 3,
  title: 'lemon',
  path: 'img/lemon.png'
 }]
 },
 methods: {
 handle: function () {
  if (this.currentIndex < 2) {
  this.currentIndex = this.currentIndex + 1
  }
 },

 handla: function () {
  if (this.currentIndex > 0) {
  this.currentIndex = this.currentIndex - 1
  }

 },
 handlc: function () {
  this.currentIndex = this.currentIndex + 1
  if (this.currentIndex > 2) {
  this.currentIndex = 0
  }

 },

 }
 })
</script>

Final result

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:
  • How to implement the Vue mouse wheel scrolling switching routing effect
  • Vue implements scrolling the mouse wheel to switch pages
  • Vue uses swiper to switch pictures by sliding left and right
  • Vue custom js picture fragment carousel switching effect implementation code
  • Vue realizes picture switching effect
  • Vue implements switching function between base64 encoded images
  • Detailed explanation of the use of Vue card-style click-to-switch image component
  • Vue implements simple image switching effect
  • Vue+js click arrow to switch pictures
  • Vue implements mouse hover to switch image src

<<:  Tutorial on installing mysql5.7.17 via yum on redhat7

>>:  Detailed explanation of Linux Namespace User

Recommend

React Native environment installation process

react-native installation process 1.npx react-nat...

Web Design: Web Music Implementation Techniques

<br />When inserting music into a web page, ...

This article will show you how to use Vue 3.0 responsive

Table of contents Use Cases Reactive API related ...

Complete step record of vue encapsulation TabBar component

Table of contents Implementation ideas: Step 1: C...

mysql join query (left join, right join, inner join)

1. Common connections for mysql INNER JOIN (inner...

MySQL Server 8.0.3 Installation and Configuration Methods Graphic Tutorial

This document records the installation and config...

Solve the problem of Navicat for Mysql connection error 1251 (connection failed)

Because what I wrote before was not detailed enou...

Detailed description of the use of advanced configuration of Firewalld in Linux

IP masquerading and port forwarding Firewalld sup...

How to mount the CD to find the rpm package under Linux

Written in front Sometimes you need to install so...

JavaScript basics of this pointing

Table of contents this Method In the object Hidde...

How to verify whether MySQL is installed successfully

After MySQL is installed, you can verify whether ...

Semantic web pages XHTML semantic markup

Another important aspect of separating structure ...

How to generate a unique server-id in MySQL

Preface We all know that MySQL uses server-id to ...