Vue implements the product tab of the product details page function

Vue implements the product tab of the product details page function

This article example shares the specific code of the product tab of Vue to realize the product details page function for your reference. The specific content is as follows

When a user clicks on a product to enter the product details page, the large image corresponding to the first small image is displayed by default. Then, when the mouse moves over the small image, the large image will also change. The effect is as follows:

Implementation code:

The template (HTML) of shopitem.vue has a large image on the top and a small image on the bottom. When the mouse moves over the small image, the getUrl event is triggered (the parameter is the show attribute and index of the small image):

item.json file (my data file, by default, the show of the first small picture is true, and the default large picture shows the first one. The paths of the large and small pictures are the same, but the picture sizes controlled by CSS are different):

The <script> method of shopitem.vue (fechData() uses vue-resource to request background data, that is, local json files. Local json files are stored in the static folder.)

The store.js file code of vuex (state management) realizes data persistence:

//store is equivalent to a warehouse. One component uses and changes data, and another component uses the data changed by the previous component. //So this is how vuex realizes data sharing between different components (different pages). //Introduce vuex
import Vue from 'vue';
import Vuex from 'vuex';
 
Vue.use(Vuex);
 
//Use Vuex to implement data persistence/* 1.state is mainly used to store data in vuex*/
var state = {
 num:1,
 info:[]
}
 
// 2. mutation contains methods, which are mainly used to change the data in state var mutations={
 Count(){
  ++state.num;
 },
 // value must be written state
 storeItemInfo(state,data){
  state.info=data;
// state.list.push(data);
 }
}
 
 // 3. Similar to calculated properties, when the count data in state is changed, the method in getters will be sent to obtain the new value var getters={
  computedCount: (state) => {
    return state.count*2;
  }
}
 
// 3.vuex instantiates Vuex.Store
const store = new Vuex.Store({
  state, /* abbreviation */
  mutations,
  getters
})
 
//4. Expose store
export default store;

This is all the code to achieve this effect, using es6 functions, vuex, and request data. Anyway, I have finally realized the benefits of es6 functions, and I hope it can help you.

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 implements product multiple selection function
  • Vue realizes the selection and reverse selection of all products in the shopping cart
  • Vue implements product specification selection function
  • Implementation code of the product "filter" function in vue mall
  • Vue+Node implements paging, sorting, and filtering of product lists, and detailed explanation of adding shopping cart functions
  • Vue implements shopping cart full selection, single selection, and display product price code examples
  • Vue implements the function of selecting product specifications

<<:  Solution to Ubuntu not being able to connect to the Internet

>>:  The simplest MySQL data backup and restore tutorial in history (Part 1) (Part 35)

Recommend

An article to teach you HTML

If you are not committed to becoming an artist, t...

Things to note when writing self-closing XHTML tags

The img tag in XHTML should be written like this:...

Do you know why vue data is a function?

Official website explanation: When a component is...

JavaScript quickly implements calendar effects

This article example shares the specific code of ...

Detailed explanation of the use of Vue h function

Table of contents 1. Understanding 2. Use 1. h() ...

Summary of MySQL development standards and usage skills

1. Naming conventions 1. Database names, table na...

MySQL 5.6.37 (zip) download installation configuration graphic tutorial

This article shares the download, installation an...

How to add a disk in Vmware: Expand the disk

This article describes how to add or expand a dis...

VUE+Canvas implements the game of God of Wealth receiving ingots

Welcome to the previous canvas game series: 《VUE ...

Nginx configuration file detailed explanation and optimization suggestions guide

Table of contents 1. Overview 2. nginx.conf 1) Co...

A brief talk about Mysql index and redis jump table

summary During the interview, when discussing abo...

jQuery realizes the sliding effect of drop-down menu

When we make a web page, sometimes we want to hav...

Use SQL statement to determine whether the record already exists before insert

Table of contents Determine whether a record alre...

JavaScript to achieve lottery effect

This article shares the specific code of JavaScri...