1、先安装less-loader

npm install less less-loader --save

2、再安装css-loader

npm install css-loader --save

3、安装上面两个之后、再安装vue-awesome-swiper(必须在前两个安装过之后安装)

npm install vue-awesome-swiper --save

4、安装完之后在package.json文件中查看一下,看是否安装上,如果安装成功,里面会显示对应的版本号

"less": "^3.8.1",
"less-loader": "^4.1.0",
"css-loader": "^0.28.11",
"vue-awesome-swiper": "^3.1.3",
5、在main.js中引入

import VueAwesomeSwiper from 'vue-awesome-swiper'

import 'swiper/dist/css/swiper.css'

Vue.use(VueAwesomeSwiper)

6、修改build\webpack.base.conf.js文件,添加下面代码

{

test: /\.less$/,

loader: 'style-loader!css-loader!less-loader'

}

7、之后就可以编写轮播组件什么的。。。送佛送到西,(轮播)组件附上:

<template>
    <div class="swiperBox">
           <swiper :options="swiperOption" ref="mySwiper">
                   <!-- 这部分放置需要渲染的内容 -->
                   <swiper-slide><div class="page">1</div></swiper-slide>
                   <swiper-slide><div class="page">2</div></swiper-slide>
                   <swiper-slide><div class="page">3</div></swiper-slide>
                   <swiper-slide><div class="page">4</div></swiper-slide>
                   <div class="swiper-pagination" slot="pagination"></div>
           </swiper>
     </div>
</template>
 
 
<script>
  import { swiper,swiperSlide } from 'vue-awesome-swiper'
  export default{
    components:{
      swiper,
      swiperSlide
    },
    data(){
      return {
        swiperOption:{
        notNextTick:true,
        pagination:{
          el:'.swiper-pagination'
        },
        loop:true,
        disableOnInteraction:true,
        autoplay:2000,
        slidesPerView:'auto',
        centeredSlides:true,
        paginationClickable:true,
        spaceBetween:30,
        onSlideChangeEnd:swiper => {
          //这个位置放置swiper的回调方法
          this.page = swiper.realIndex+1;
          this.index = swiper.realIndex;
        }
      }
    }
  },
  computed:{
    //定义这个swiper对象
    swiper(){
      return this.$refs.mySwiper.swiper;
    }
  },
  mounted() {
    //这边就可以使用swiper这个对象或使用swiper官网中的方法
    var that=this;
    this.swiper.slideTo(0,0,false);
    //自动播放
    setInterval(function(){
      that.swiper.slideNext()
    },2000)
  },
}
</script>
 
<style scoped>
  .swiperBox{
    width:100%;
    height:300px;
  }
  .page{
    width:100%;
    height:300px;
    background:pink;
  }
</style>

vue中引入awesomeswiper的方法以及编写轮播组件的更多相关文章

  1. Vue编写轮播组件引入better-scroll插件无法正常循环轮播

    临近过年还是发个博客表示一下自己的存在感,这段时间公司突然说想搞小程序,想到这无比巨大的坑就只能掩面而泣,于是乎这段时间在学习小程序开发.关于标题所说的是有老铁问的,我也跟着网上的代码码了一遍然后发现 ...

  2. vue-cli中引入jquery的方法

    vue-cli中引入jquery的方法 以前写vue项目都没有引入过jquery,今天群里面的一位小伙伴问了我这个问题,我就自己捣鼓了一下,方法如下: 我们先进入webpack.base.conf.j ...

  3. vue中引入mintui、vux重构简单的APP项目

    最近在学习vue时也了解到一些常用的UI组件,有用于PC的和用于移动端的.用于PC的有:Element(饿了么).iView等:用于移动端APP的有Vux.Mint UI(饿了么).Vant(有赞团队 ...

  4. vue中mixins的使用方法和注意点(详)

    mixins基础概况 vue中的解释是这样的,如果觉得语言枯燥的可以自行跳过嘿~ 混入 (mixins): 是一种分发 Vue 组件中可复用功能的非常灵活的方式.混入对象可以包含任意组件选项.当组件使 ...

  5. HTML中引入CSS的方法

    在HTML中引入CSS的方法主要有四种,它们分别是行内式.内嵌式.链接式和导入式. 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用. 2.内嵌式 ...

  6. vue中引入babel步骤

    vue中引入babel步骤 vue项目中普遍使用es6语法,但有时我们的项目需要兼容低版本浏览器,这时就需要引入babel插件,将es6转成es5. 1.安装babel-polyfill插件 npm ...

  7. vue中添加util公共方法&&ES6之import、export

    vue中添加util公共方法&&ES6之import.export https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Re ...

  8. vue中引入json数据,不用本地请求

    1.我的项目结构,需要在Daily.vue中引入daily.js中的json数据 2.把json数据放入一个js文件中,用exports导出,vscode的json格式太严格了,很多数据,调了一个多小 ...

  9. vue中引入mui报Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them的错误

    在vue中引入mui的js文件的时候,报如下的错误: 那是因为我们在用webpack打包项目时默认的是严格模式,我们把严格模式去掉就ok了 第一步:npm install babel-plugin-t ...

随机推荐

  1. windows应急响应入侵排查思路

    0x00 前言 ​ 当企业发生黑客入侵.系统崩溃或其它影响业务正常运行的安全事件时,急需第一时间进行处理,使企业的网络信息系统在最短时间内恢复正常工作,进一步查找入侵来源,还原入侵事故过程,同时给出解 ...

  2. NFS 配置文件

    NFS 配置文件是 /etc/exports,内容如下: [root@localhost ~]# cat /etc/exports /data 192.168.216.129/32(rw,sync,a ...

  3. [Ubuntu] 如何在 Lubuntu 安装 python-spidermonkey

    SpiderMonkey 是由 Mozilla 开发的 Javascript 引擎,它由 C/C++ 编写而成.Mozilla 在其多个产品中使用了该引擎,包括 Firefox 浏览器. python ...

  4. oracle数据据 Python+Pandas 获取Oracle数据库并加入DataFrame

    import pandas as pd import sys import imp imp.reload(sys) from sqlalchemy import create_engine impor ...

  5. API权限控制与安全管理

     摘自网上 一.API权限控制范围 1.首先验证web端请求参数: (1)web请求参数:渠道.ServiceName.版本.Airline.时间戳(yyyyMMddhhmmssSSS).reqXML ...

  6. (转载)Recyclerview | Intent与Bundle在传值上的区别 | 设置布局背景为白色的三种方法

    用Recyclerview实现列表分组.下拉刷新以及上拉加载更多  http://www.jianshu.com/p/be62ce21ea57 Intent与Bundle在传值上的区别http://b ...

  7. 《转载》脚本实现从客户端服务端HTTP请求快速分析

    本文转载自https://www.imooc.com/article/14107 首先我想介绍下,分享这个脚本的用处: 当客户告知我们,一个页面http://www.xxx.com 有问题时,作为PE ...

  8. Clock skewdetected. Your build may be incomplete.

    解决方法: find . -type f | xargs -n touch make clean make

  9. sklearn 中的 Pipeline 机制 和FeatureUnion

    一.pipeline的用法 pipeline可以用于把多个estimators级联成一个estimator,这么 做的原因是考虑了数据处理过程中一系列前后相继的固定流程,比如feature selec ...

  10. <转>Python: and、or以及and-or

    转自 http://www.cnblogs.com/BeginMan/p/3197123.html 一.and: 在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不 ...