zoukankan      html  css  js  c++  java
  • vue使用Vant UI中的swiper组件及传值

    子组件SwiperBanner

    <!--  -->
    <template>
      <div class="swiper">
        <van-swipe :autoplay="3000"
                   indicator-color="white">
          <van-swipe-item v-for="(item,index) in imgList"
                          :key="index">
            <img :src="item.img"
                 alt=""
                 title="" />
          </van-swipe-item>
        </van-swipe> 
      </div>
    </template>
    
    <script>
    import Vue from 'vue';
    import { Swipe, SwipeItem } from 'vant';
    Vue.use(Swipe).use(SwipeItem);
    export default {
      name: 'swiper',
      props: {
        imgList: {
          type: Array,
          required: true
        },
        aaa: '',
      },
      data () {
        return {
        };
      },
    }
    </script>
    <style lang='scss'  >
    .swiper {
       100%;
      height: 4rem;
      .van-swipe {
        height: 4rem;
        img {
          height: 100%;
           100%;
        }
      }
    }
    </style>

    父组件

    <!--  -->
    <template>
      <div class="goodsDetails">
        商品详情{{goodsId}}
        <SwiperBanner :imgList="imgList"
                      :aaa="aaa"></SwiperBanner>
      </div>
    </template>
    
    <script> 
    import SwiperBanner from "@/components/SwiperBanner.vue"
    export default {
      components: {
        SwiperBanner,
      },
      data () {
        return {
          goodsId: '',
          imgList: [
            { img: "https://img.yzcdn.cn/vant/apple-1.jpg" },
            { img: "http://file02.16sucai.com/d/file/2014/0704/e53c868ee9e8e7b28c424b56afe2066d.jpg" },
            { img: "https://img.yzcdn.cn/vant/apple-1.jpg" },
            { img: "http://file02.16sucai.com/d/file/2014/0704/e53c868ee9e8e7b28c424b56afe2066d.jpg" },
          ],
          aaa: 'wwwww'
        };
      },
      mounted () {
        var that = this
        that.getGoodsId()
      },
      methods: {
        // 获取参数
        getGoodsId () {
          var that = this
          that.goodsId = this.$route.query.goodsId
        }
      },
    }
    
    </script>
    <style lang='scss'  >
    </style>
  • 相关阅读:
    扁平化设计五大原则
    扁平化
    如何调试PHP程序
    Java中的协变与逆变
    Java的equals方法实现及其细节
    Java的clone方法效率问题
    Mac的Terminal中无法使用mvim解决方案
    SC.Lab3对于Factory的构建过程(from HIT)
    关于Lab3中对于正则表达式的应用
    关于Java构造类与对象的思考
  • 原文地址:https://www.cnblogs.com/xiaoxiao2017/p/12048643.html
Copyright © 2011-2022 走看看