想在vue項目中使用vue-awesome-swiper實現(xiàn)相冊查看功能,測試的時候發(fā)現(xiàn)使用寫死的圖片src 時手勢縮放沒有問題,但是圖片src集合換到從后臺獲取到再賦值的,手勢縮放就不起作用了,不知道是什么原因。(代碼詳情見思否SF:vue-awesome-swiper 手勢縮放無效 )vue template中:style:<style>????.viewImg?.swiper-slide?img?{????width:?100%;????}</style>html template:<div?class="viewImg"?>????????????<a?class="btn-close?f-r"><img?src="/images/icon-close.png"?@click="closeViewer"?alt="關(guān)閉"?title="關(guān)閉"></a>????????????<swiper?:options="swiperOption"?ref="mySwiper">????????????????<swiper-slide?v-for="img?in?images"?:key="img.id">????????????????????<div?class="swiper-zoom-container">????????????????????????<img?:data-src="img.smallSizeUrl"?class="swiper-lazy">????????????????????</div>????????????????</swiper-slide>????????????????<div?class="swiper-button-prev"?slot="button-prev"></div>????????????????<div?class="swiper-button-next"?slot="button-next"></div>????????????</swiper>????????</div>js:import?'swiper/dist/css/swiper.css'??;????
import?{?swiper,?swiperSlide?}?from?'vue-awesome-swiper';????
export?default?{????????
components:?{????????????
swiper,????????????
swiperSlide????????
},????????
data()?{????????????
return?{
swiperOption:?
{????????????????????
allowTouchMove:?true,????????????????????
width:?window.innerWidth,????????????????????
notNextTick:?false,????????????????????
observer:true,//修改swiper自己或子元素時,自動初始化swiper????????????
observeParents:true,//修改swiper的父元素時,自動初始化swiper????????????????????loadPrevNext:?true,????????????????????
lazy:?{????????????????????loadPrevNext:?true,??????????????????????},????????????????????
lazyLoading?:?true,????????????????????lazyLoadingInPrevNext:?true,?//?設(shè)置為true允許將延遲加載應(yīng)用到最接近的slide的圖片(前一個和后一個slide)。????????????????????
zoom:?true,????????????????????grabCursor:?true,?//?設(shè)置為true時,鼠標(biāo)覆蓋Swiper時指針會變成手掌形狀,拖動時指針會變成抓手形狀。(根據(jù)瀏覽器形狀有所不同)????????????????????
pagination:?{????????????????????????el:?'.swiper-pagination'????????????????????},????????????????????
navigation:?{????????????????????????nextEl:?'.swiper-button-next',????????????????????????
prevEl:?'.swiper-button-prev'????????????????????}????????????????}????????????
}????????
},????????//定義這個sweiper對象????????
computed:?{????????????
swiper()?{??????????????
return?this.$refs.mySwiper.swiper;?}?},????????
mounted?()?{?
//這邊就可以使用swiper這個對象去使用swiper官網(wǎng)中的那些方法????????????
//?this.swiper.slideTo(0,?1,?false);????????????
},????????
props:?{????????????
images:?{????????????????
required:?true????????????
}????????
},????????
methods:{????????????
closeViewer:?function(){????????????????
this.viewImg?=?false;????????????
}????????
}????
}(慕課的代碼編輯太難看了)
vue-awesome-swiper 手勢縮放無效
Tsukiis
2018-08-09 11:11:11