一、vue-awesome-swiper的使用

  1、在项目中全局引用 

import VueAwesomeSwiper from 'vue-awesome-swiper'
// require styles
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper /* { default global options } */)

引入之后,在文件中直接使用

       <swiper :options="swiperOption" ref="mySwiper" @someSwiperEvent="callback">
<!-- slides --> <swiper-slide v-for="(item,index) in newCards" :key="index">
<div class="swiper-slide-item">
<div class="slide-img-wrap">
<img :src="item.image" />
</div>
</div>
</swiper-slide>
<!-- Optional controls -->
<!-- <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>
<div class="swiper-scrollbar" slot="scrollbar"></div> -->
</swiper>

2、在组件中局部

文件中导入

 import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'  

注册组件

components: {
swiper,
swiperSlide
},  

html中的写法和全局引入时的一样 

二、问题

   1、swiper外加了v-if,无法读取this.$refs,也就是通过this.$refs无法拿到swiper对象,无法在滑动卡片之后拿到我想要的当前的card的位置,去掉v-if通过this.$refs可以读到swiper对象。

      打印this,可以看到有swiper对象,但是读出来却没有

data() {
return {
swiperOption: {
width: 234,
onSlideChangeStart: swiper => {
let i = swiper.activeIndex;
this.currentCardId = i
console.log('index:', i)
},
}
}
},
mounted() {
// current swiper instance
// 然后你就可以使用当前上下文内的swiper对象去做你想做的事了
    console.log(this, this.swiper, this.$refs, this.$refs.mySwiper)
// console.log('this is current swiper instance object', this.swiper)
// this.swiper.slideTo(3, 1000, false)
},

当前版本用的是swiper3,可以使用onSlideChangeStart方法来监听事件,从而获取到swiper对象,拿到当前元素的属性。

2、给swiper-slide动态添加class类,css无效。

    所以我最终将需要给偏移值的第一个swiper-slide直接写死了class

总结:这两个问题都涉及到渲染问题。

未完待续。。。

  

记使用vue-awesome-swiper遇到的一些问题的更多相关文章

  1. vue引入swiper vue使用swiper vue脚手架使用swiper /引入js文件/引入css文件

    vue引入swiper  vue使用swiper  vue脚手架使用swiper /引入js文件/引入css文件 ------------------------------------------- ...

  2. Vue与swiper想结合封装全屏轮播插件

    项目需求介绍: 1.页面图文混排, 2.点击图片后全屏展示图片,并在底部显示文字,如果没有则不显示 3.关闭全屏后依然停留在上次浏览的位置 4.浏览图片时,不管点击的哪张图片,全屏展示的时候也要显示这 ...

  3. vue 使用swiper的一些问题(页面渲染问题)

    //Swiper上下滚动初始化 swiper_init(){ this.$nextTick(function(){ var mySwiper = new Swiper ('.swiper-contai ...

  4. vue awaresome swiper的使用

    main.jsimport VueAwesomeSwiper from 'vue-awesome-swiper'import 'swiper/dist/css/swiper.css'Vue.use(V ...

  5. 小程序和Vue利用swiper实现icons分页显示--动态计算

    这里发现小程序实现步骤,Vue与之类似 先上效果图: <view class="icons"> <swiper indicator-dots="true ...

  6. vue使用swiper模块滑动时报错:[Intervention] Ignored attempt to cancel a touchmove event with cancelable=false, for example becaus

    报错: vue报这个错 [Intervention] Ignored attempt to cancel a touchmove event with cancelable=false, for ex ...

  7. 轮播模仿臭美APP,vue,swiper

    介绍:轮播使用了swiper,重要用于移动端滑动,详情可查看官网 1.首先用npm安装        npm install swiper 2.main.js 中引入CSS     import 's ...

  8. vue封装swiper

    参考:https://github.com/surmon-china/vue-awesome-swiper npm install vue-awesome-swiper --save 全局引入 imp ...

  9. vue添加swiper的正确方式亲测---切图网

    在vue项目中,我们在做图片轮播的方式和传统切图不同,传统切图中我们一般采用非常强大的swiper来完成,而在vue中一般依赖vue-awesome-swiper组件来完成(vue-awesome-s ...

  10. Vue整合swiper报错Could not compile template .....swiper\dist\css\swiper.css解决办法

    问题描述 今天做一个前端项目,安装幻灯片插件vue-awesome-swiper后 运行npm run dev 后报错如下: `ERROR Could not compile template E:\ ...

随机推荐

  1. win都是数据更新

    1:一种新的类型: 枚举: 枚举是一种描述性的名称 定义一组有限的值,不能包含方法 对可能的值进行约束 枚举保证了赋值的合理性 2:   public enum Grader(枚举的名称){ Male ...

  2. Java中final的用法总结

    1.         修饰基础数据成员的final 这是final的主要用途,其含义相当于C/C++的const,即该成员被修饰为常量,意味着不可修改.如java.lang.Math类中的PI和E是f ...

  3. this关键字的使用8/22

    实质就是:this代表当前对象目录: 1.this(name) 调用同一个类中参数为 public Person(String name)这个构造方法 2.this.say() 同一个类中,某一个方法 ...

  4. protobuf GetExtension

    get extention values from  proto file value, err := proto.GetExtension(imp, openrtb.E_Imp) if err != ...

  5. Jenkins部署项目

    第三首先部署好Jenkins 新建一个自由项目 svn地址,credentials是指认证,点击Ad那里添加,并选择username和password方式,并输入用户名和密码 H/5 * * * * ...

  6. shell入门(二)——面试题实例

    [~/shell]$ cat one.sh #!/bin/bash path=/root/shell/test.txt if [ ! -f $path ] //检测文件是否存在,如果不存在,把内容改为 ...

  7. lapis 1.7.0 更好的openresty 版本兼容以及安全数据库支持

    lapis 1.7.0 今年4月2号就发布了,一直没有注意,今天看到changelog就简单的进行了一个 测试(主要是与openresty版本的测试,新变更后边会有) 使用docker-compose ...

  8. Space Shooter 学习

    using UnityEngine; using System.Collections; /// <summary> /// 背景滚动 /// </summary> publi ...

  9. http 2.0 新特性

    http 2.0 新特性: 二进制分帧 首部压缩 流量控制 多路复用 请求优先级 服务器推送 出处:https://juejin.im/post/5a4dfb2ef265da43305ee2d0

  10. ElasticSearch story(二)

    调优一个问题,碰到了一个坎:大家看一下下面两个字符串: 2018-10-16 18:01:34.000 abcdewfrwfe 2018-10-16 18:01:50.123 testAmily012 ...