• vu3.0 + ts + swiper6 的问题


    起初 vue3.0 + ts 中安装swiper 6.4.5 一直报错,后终于解决 直接上代码

    shims-vue.d.ts

      首先 要在   shims-vue.d.ts  文件中 添加  
    /* eslint-disable */
    declare module '*.vue' {
      import type { DefineComponent } from 'vue'
      const component: DefineComponent<{}, {}, any>
      export default component
    }
    
    
    declare module 'swiper/vue'
    declare module 'swiper'
    

      然后 

    <template>
      <swiper
        :autoplay="swiperOptions.autoplay"
        :loop="swiperOptions.loop"
        :speed="swiperOptions.speed"
        :pagination="swiperOptions.pagination"
        class="swiper-container"
      >
        <swiper-slide class="swipe-img">
          <img
            src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/150835/21/14707/172863/5ff6b469E72637b85/4f80b1d32d628ed3.jpg!q70.jpg.dpg"
          />
        </swiper-slide>
        <swiper-slide class="swipe-img">
          <img
            src="//m.360buyimg.com/mobilecms/s700x280_jfs/t1/141734/35/19747/233355/5fe411b7Ee9e142c1/3c081878ff6cdf72.jpg!cr_1125x445_0_171!q70.jpg.dpg"
          />
        </swiper-slide>
      </swiper>
    </template>
    
    <script lang="ts">
    import { defineComponent, reactive, toRefs } from "vue";
    import SwiperCore, { Autoplay, Pagination } from 'swiper';
    import { Swiper, SwiperSlide } from 'swiper/vue';
    import 'swiper/swiper.min.css';
    import 'swiper/components/pagination/pagination.less';
    SwiperCore.use([Autoplay, Pagination]);
    
    export default defineComponent({
      name: "about",
      components: {
        Swiper,
        SwiperSlide,
      },
      setup() {
        const state = reactive({
          swiperOptions:{
            autoplay: {
              delay: 3000,
              disableOnInteraction: false
            },
            loop: true,
            speed: 1000,
            pagination: {
              clickable: true
            }
          }
        })
        return { ...toRefs(state) };
      }
    });
    </script>
    <style lang="less">
    img {
       100%;
      height: 100%;
    }
    .swiper-container {
       100%;
      height: 180px;
      .swipe-img {
        height: 100%;
      }
    }
    </style>
    

      

  • 相关阅读:
    我爱Java系列之---【SpringBoot打成war包部署】
    279. Perfect Squares
    矩阵dfs--走回路
    112. Path Sum
    542. 01 Matrix
    106. Construct Binary Tree from Inorder and Postorder Traversal
    105. Construct Binary Tree from Preorder and Inorder Traversal
    Invert Binary Tree
    563 Binary Tree Tilt
    145 Binary Tree Postorder Traversal
  • 原文地址:https://www.cnblogs.com/qq735675958/p/14272771.html
Copyright © 2020-2023  润新知