最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

vue+swiper组件化开发的相关步骤

来源:动视网 责编:小采 时间:2020-11-27 19:54:36
文档

vue+swiper组件化开发的相关步骤

vue+swiper组件化开发的相关步骤:这次给大家带来vue+swiper组件化开发的相关步骤,vue+swiper组件化开发的注意事项有哪些,下面就是实战案例,一起来看一下。swiper的组件<template> <p class="swiper-container"> <p class=&qu
推荐度:
导读vue+swiper组件化开发的相关步骤:这次给大家带来vue+swiper组件化开发的相关步骤,vue+swiper组件化开发的注意事项有哪些,下面就是实战案例,一起来看一下。swiper的组件<template> <p class="swiper-container"> <p class=&qu


这次给大家带来vue+swiper组件化开发的相关步骤,vue+swiper组件化开发的注意事项有哪些,下面就是实战案例,一起来看一下。

swiper的组件

<template>
 <p class="swiper-container">
 <p class="swiper-wrapper">
 <p class="swiper-slide" v-for="item in swiper"><img :src="item.room_src" alt=""></p>
 <!--<p class="swiper-slide" v-for="item in test"><img :src="item.room_src" alt=""></p>-->
 </p>
 </p>
</template>
<script>
 import Swiper from 'swiper'
 export default {
 name: 'swiper',
 data() {
 return {
 mySwiper: null,
// test: [
// "https://rpic.douyucdn.cn/acrpic/171024/288016_0921.jpg",
// "https://rpic.douyucdn.cn/acrpic/171024/748396_0924.jpg",
// "https://rpic.douyucdn.cn/acrpic/171024/453751_0922.jpg",
// "https://rpic.douyucdn.cn/acrpic/171024/79663_0920.jpg"
// ]
 }
 },
 props: ['swiper'], //swiper的就是test这个数据传递来的
 methods: {
 _initSwiper() {
 this.mySwiper = new Swiper('.swiper-container', {
 autoplay: 5000,//可选选项,自动滑动
 })
 },
 _updateSwiper() {
 this.$nextTick(() => {
 this.mySwiper.update(true); //swiper update的方法
 })
 },
 swiperUpdate() {
 if (this.mySwiper) { //节点存在
 this._updateSwiper(); //更新
 } else {
 this._initSwiper(); //创建
 }
 },
 },
 watch: {
 //通过props传来的数据 和 组件一加载节点就创建成功 二者不是同步,实时监听的swiper(传递的值)的变化
 swiper() {
 this.swiperUpdate();
 }
 },
 mounted() {
 this.swiperUpdate(); //页面一加载拉去数据创建节点
 }
 }
</script>
<style lang="scss" scoped>
 .swiper-container {
 width: 100%;
 height: 4rem;
 margin-top: 0.9rem;
 .swiper-wrapper {
 width: 100%;
 height: 100%;
 .swiper-slide {
 background-size: cover;
 width: 100%;
 height: 4rem;
 img {
 width: 100%;
 height: 100%;
 }
 }
 }
 }
</style>

home.vue 调用的组件方法

//html
 <swiper :swiper="roomList.slice(6,10)" ></swiper>
//js
 import swiper from 'components/swiper/swiper'
 components: {
 swiper
 },

问题:如果单纯的调用_initSwiper的方法,会发现页面是不能滚动的,但是页面随便修改东西,然后保存的swiper又可以滚动的,这个个原因是初始swiper的节点没有创建成功,值页面有穿进去的,一层一层的可以打印swiper的值为空的,当修改东西值就能传递进去的,所以的这里的我们需要通过判断节点是否成功来update siwper的方法

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

让.vue在Sublime Text新建模板内高亮

Node.js环境变量process.env使用详解

文档

vue+swiper组件化开发的相关步骤

vue+swiper组件化开发的相关步骤:这次给大家带来vue+swiper组件化开发的相关步骤,vue+swiper组件化开发的注意事项有哪些,下面就是实战案例,一起来看一下。swiper的组件<template> <p class="swiper-container"> <p class=&qu
推荐度:
标签: 方法 VUE 开发
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top