使用vue完成移动端轮播图:vue-awesome-swiper3.x 基本使用

本文介绍了如何使用vue-awesome-swiper3.x在移动端创建轮播图。首先,讲解了vue-awesome-swiper是基于swiper且大多数swiper属性适用于此库。接着,详细阐述了安装和引入swiper的两种方法,包括全局引入和组件内引入。最后,讨论了轮播图的实现。

一、说明

vue-awesome-swiper是基于swiper的,安装不同版本的vue-awesome-swiper对应不同的swiper,所以swiper里面的属性多数能应用到vue-awesome-swiper中,也可以根据swiper文档来设置vue-awesome-swiper属性;
swiper挂网:https://www.swiper.com.cn/,本次使用的版本"vue-awesome-swiper": "^3.1.3"

二、安装

npm install vue-awesome-swiper@3.1.3 --save//指定安装版本
npm install vue-awesome-swiper --save // 默认安装最新的

三、引入

引入有两种方式

1.在main.js文件中全局引入
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper)
2.在组件中引入
import { swiper, swiperSlide } from "vue-awesome-swiper";
require("swiper/dist/css/swiper.css");
export default {
	name: "swiper",
    components:{
    	swiper,
        swiperSlide
   }

四、轮播图

<template>
	<div>
		<section class="swiper">
			<swiper :options="swiperOption">
				<swiper-slide  class="swp-silde" v-for="(item, index) in swiperList" :key="index" data-id="item.id">
				<img class="swp-img" :src="item.imgUrl" alt=""></swiper-slide>
				<div class="swiper-pagination" slot="pagination"></div>
			</swiper>
		</section>
	</div>
</template>	

<script>
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
   name: "Swiper",
   components: {
     swiper,
     swiperSlide,
   },
   data(){
      return {
          swiperOption: {
            pagination: { el: '.swiper-pagination' },
            autoplay: {},
          },
          swiperList: [{
            "id": "0001",
            "imgUrl": "http://img1.qunarzz.com/piao/fusion/1708/7c/c0b9acba07764302.jpg_750x200_389436b7.jpg"
          }, {
            "id": "0002",
            "imgUrl": "http://img1.qunarzz.com/piao/fusion/1805/13/6332699c44387902.jpg_750x200_b7afa4f8.jpg"
          }, {
            "id": "0003",
            "imgUrl": "http://img1.qunarzz.com/piao/fusion/1805/3b/ef86879aa50e3002.jpg_750x200_2a108508.jpg"
          }, {
            "id": "0004",
            "imgUrl": "http://img1.qunarzz.com/piao/fusion/1806/c1/a8a7d6b08a69c002.jpg_750x200_59bdc9ae.jpg"
          }, {
            "id": "0005",
            "imgUrl": "http://img1.qunarzz.com/piao/fusion/1806/5a/a7fc8e091190d602.jpg_750x200_e3aae50d.jpg"
          }],
      }
   }
},
created(){
   //只有一张图片时不轮播
   this.swiperOption.autoplay = this.swiperList.length != 1 ? {
   		disableOnInteraction: false, // 用户操作swiper之后,是否禁止autoplay
   		delay: 3000, // 自动切换的时间间隔(单位ms)
   } : false
},
</script>
引用:npm ERR! 404 Not Found - GET https://registry.npmmirror.com/@vue/vue-loader-v15 - [NOT_FOUND] @vue/vue-loader-v15 not found vue 安装npm i element-ui -S 等 组件 报错 npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmmirror.com/@vue/vue-loader-v15 - [NOT_FOUND] @vue/vue-loader-v15 not found npm ERR! 404 npm ERR! 404 &#39;@vue/vue-loader-v15@15.10.0&#39; is not in the npm registry. npm ERR! 404 You should bug the author to publish it (or use the name yourself!) npm ERR! 404 It was specified as a dependency of &#39;@vue/cli-service&#39; npm ERR! 404 npm ERR! 404 Note that you can also install from a npm ERR! 404 tarball, folder, http url, or git url. 根据引用的内容,这个错误是由于找不到vue-awesome-swiper的tarball数据所导致的。vue-awesome-swiper的tarball数据位于http://172.168.251.67:4873/vue-awesome-swiper/-/vue-awesome-swiper-3.1.3.tgz。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [npm install -g cnpm --registry=https://registry.npm.taobao.org报错](https://blog.csdn.net/qq_36853469/article/details/99900961)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [ist的matlab代码-gitlab-uberspace-tutorial:如何在https://uberspace.de上安装GitLab](https://download.csdn.net/download/weixin_38543120/19078868)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [ 404 Not Found - GET https://registry.npmmirror.com/@vue%2fvue-loader-v15 - [NOT_FOUND] @vue](https://blog.csdn.net/qq_51307593/article/details/127484795)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值