Solve the problem of using swiper plug-in in vue

Solve the problem of using swiper plug-in in vue

Since I used this plugin when writing a demo and encountered some problems, I simply checked the usage of the plugin and some common errors.

1. Get .../maps/swiper.min.js.map 500 (Internal Server Error) appears

Source Map files missing when using min version

1. Disable Source Map prompt and delete the last line of swiper.min.js file //# sourceMappingURL=swiper.min.js.map

2. If you need to use Source Map, the complete package contains the file swiper.min.js.map, please put it in the corresponding location. About Source Map

2. The video cannot be rotated automatically and the page breaks are not displayed.

Solution:

install plus the version number.

Due to the version problem of the vue-awesome-swiper plugin package, the left and right arrow clicks may fail.

The solution is as follows:

npm uninstallvue-awesome-swiper --save

npm [email protected] --save

After installing version 3.1.3, restart and check to solve the problem

3. Error in render: "TypeError: Cannot set property 'params' of undefined" appears --- It is related to the version number. The first letter of version 4.0 is capitalized, and the first letter of version 3.0 is lowercase.

Answer link: https://github.com/surmon-china/vue-awesome-swiper/issues/499

如果使用的是3.x版本[email protected] , the import code is as follows:

import { swiper, swiperSlide } from 'vue-awesome-swiper

如果使用的是4.x版本[email protected] , the import code is as follows:

import { Swiper, SwiperSlide } from 'vue-awesome-swiper

4. Uncaught ReferenceError: Swiper is not defined at...

Maybe the JS file is not loaded or the location is wrong.

The solution is as follows:

Download the file package and load Swiper's JS and CSS files on the page, or use Swiper's CDN service to load the files, and then initialize Swiper after loading.

Vue中使用Swiper的用法如下:

The first one: global import

In main.js

import VueAwesomeSwiper from 'vue-awesome-swiper';
 import "swiper/dist/css/swiper.css";
 
 Vue.use(VueAwesomeSwiper)

The second method: local introduction

In the js file of the used module

import { swiper, swiperSlide } from "vue-awesome-swiper";
import "swiper/dist/css/swiper.css";
 
export default {
    
    components:
        swiper,
        swiperSlide
    }
}

In the .vue file, the left and right arrows are placed outside the carousel. The code is as follows:

<swiper class="swiper" :options="swiperOption" >
      <swiper-slide class="swiper-slide" v-for="item in 4" :key="item">
          <div class="swiper-content">{{item}}</div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
</swiper>
 
 <div class="swiper-button-prev" slot="button-prev"></div>
 <div class="swiper-button-next" slot="button-next"></div>

In the .vue file, the left and right arrows are placed inside the carousel. The code is as follows:

<swiper class="swiper" :options="swiperOption" >
      <swiper-slide class="swiper-slide" v-for="item in 4" :key="item">
          <div class="swiper-content">{{item}}</div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
      <div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
</swiper>

The configuration information of swiperOption above is as follows. For details, please refer to the official website: https://www.swiper.com.cn/api/index.html

This is the end of this article about the error problem of using the swiper plug-in in vue. For more relevant content about using the swiper plug-in in vue, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Example of using swiper plugin to implement carousel in Vue
  • Solve the problem of using swiper plug-in in vue and the usage of swiper in vue
  • How to use the react-native package plug-in swiper
  • Solve the problem that the Swiper plug-in cannot slide in Angular.js
  • Detailed explanation of how to use the vue-awesome-swiper slider plugin
  • Example of using swiper plugin introduced in vue
  • Let's learn about the use and introduction of the Swiper plug-in

<<:  Detailed steps for installing MySQL using cluster rpm

>>:  Nginx load balancing configuration, automatic switching mode when downtime occurs

Recommend

Sample code for CSS image animation effects (photo frame)

This article introduces the sample code of CSS pi...

Docker starts Redis and sets the password

Redis uses the apline (Alps) image of Redis versi...

Use viewport in meta tag to define screen css

<meta name="viewport" content="w...

Introduction to the usage of common XHTML tags

There are many tags in XHTML, but only a few are ...

HTML tag default style arrangement

html, address,blockquote,body, dd, div,dl, dt, fie...

Issues and precautions about setting maxPostSize for Tomcat

1. Why set maxPostSize? The tomcat container has ...

How to use wangEditor in vue and how to get focus by echoing data

Rich text editors are often used when doing backg...

Display flex arrangement in CSS (layout tool)

Regarding display: flex layout, some people have ...

Linux uses NetworkManager to randomly generate your MAC address

Nowadays, whether you are on the sofa at home or ...

Summary of Linux Logical Volume Management (LVM) usage

Managing disk space is an important daily task fo...

Vue3 (III) Website Homepage Layout Development

Table of contents 1. Introduction 2. Actual Cases...

React implements paging effect

This article shares the specific code for React t...

How to reset the initial value of the auto-increment column in the MySQL table

How to reset the initial value of the auto-increm...