vue3 + vite + ts 安装使用 swiper(效果图在最后)

项目中需要一个轮播图,但是又不需要自动播放,而且能在移动端能滑动切换,所以就想到了用swiper,本来如果在pc端的话,只要使用element里面的走马灯组件就可以了.但是element走马灯不兼容移动端的滑动切换.

网上找了很多相关的文章,但是因为版本的问题都不能正常引入插件的css报错,导致不能正常使用,最终摸索出来一个能使用的版本,希望能给大家带来帮助

1.安装 swiper (一定要指定版本!!!)

npm install swiper@7.4.1

 2.在组件中引用(vue代码)

<template>
  <Swiper
      :modules="modules"
      @swiper="onSwiper"
      :slidesPerView="4.3"
      :autoplay="{ delay: 2500, disableOnInteraction: true }"
      :loop="false"
      :space-between="10"
  >
    <swiper-slide>Slide 1</swiper-slide>
    <swiper-slide>Slide 2</swiper-slide>
    <swiper-slide>Slide 3</swiper-slide>
    <swiper-slide>Slide 4</swiper-slide>
    <swiper-slide>Slide 5</swiper-slide>
    <swiper-slide>Slide 6</swiper-slide>
  </Swiper>
</template>

3.在组件中使用(ts代码) 

<script setup lang="ts">
import {toRaw, onMounted} from 'vue'
import {Swiper, SwiperSlide} from "swiper/vue";
import {Navigation, Pagination, Scrollbar, A11y} from 'swiper';
import "swiper/css";

const modules = [Navigation, Pagination, Scrollbar, A11y];

const onSwiper = (swiper: any) => {
  console.log(swiper);
};
</script>

4.一些css样式(可以自定义,这里只做示范) 

.swiper-slide {
  height: 100px;
  line-height: 100px;
  font-size: 30px;
  text-align: center;
  background-color: pink;
}

.swiper::v-deep .swiper-pagination .swiper-pagination-bullet {
  background: rgb(255, 255, 255);
}

.swiper::v-deep .swiper-pagination .swiper-pagination-bullet-active {
  background: rgb(255, 255, 255);
}

 5.效果图(右侧是打印的一些信息)

以上就是swiper在vue3+vite+ts项目的配置和使用,谢谢一件三连哦~~

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue 3 + Vite + TypeScript中使用EditableProTable组件可以按照以下步骤进行: 1. 首先,确保你已经安装了Ant Design Vue和EditableProTable组件。你可以使用以下命令进行安装: ```bash npm install ant-design-vue@next npm install @ant-design/pro-table@next ``` 2. 在你的Vue组件中引入EditableProTable组件和相应的样式: ```vue <template> <a-table-pro :columns="columns" :request="fetchData" :rowKey="record => record.id" :pagination="pagination" :loading="loading" :options="options" :actionRef="actionRef"></a-table-pro> </template> <script> import { defineComponent, ref } from 'vue' import { EditableProTable } from '@ant-design/pro-table' export default defineComponent({ components: { ATablePro: EditableProTable, }, setup() { const columns = [ // 列配置 ] const fetchData = async (params) => { // 发起请求获取数据 } const loading = ref(false) const pagination = ref({ current: 1, pageSize: 10, }) const options = ref({}) const actionRef = ref(null) return { columns, fetchData, loading, pagination, options, actionRef, } }, }) </script> <style lang="less"> @import '~@ant-design/pro-table/dist/component.less'; </style> ``` 3. 根据你的需要,配置EditableProTable的列配置和数据请求逻辑。你可以根据Ant Design Vue的Table组件和EditableProTable的文档进行配置。 这样,在Vue 3 + Vite + TypeScript中,你就可以使用EditableProTable组件了。根据你的实际情况,你可能需要进行一些额外的配置和样式调整。请参考Ant Design Vue和EditableProTable的文档进行进一步的学习和调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值