如果你不想将Swiper文件放在你的项目中,可以使用Swiper的CDN服务。
风险提示:CDN由于不稳定性,在生产环境中请谨慎使用。
Swiper6-8,更改数字可切换不同版本,如@8、@8.0.4,不加版本号为最新版本。
<link rel="stylesheet" href="https://unpkg.com/swiper@8/swiper-bundle.css">
<link rel="stylesheet" href="https://unpkg.com/swiper@8/swiper-bundle.min.css">
<script src="https://unpkg.com/swiper@8/swiper-bundle.js"> </script>
<script src="https://unpkg.com/swiper@8/swiper-bundle.min.js"> </script>
<script src="https://unpkg.com/swiper@8/swiper-bundle.min.js.map"> </script>
ES 模块
<script type="module">
import Swiper from 'https://unpkg.com/swiper@8/swiper-bundle.esm.browser.min.js'
const swiper = new Swiper(...)
</script>
Swiper5/Swiper4,要将5.x.x改成相应的版本,如5.4.5或4.5.1版本(4无esm的CDN)
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/css/swiper.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/css/swiper.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/js/swiper.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/js/swiper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/js/swiper.esm.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/5.x.x/js/swiper.esm.bundle.js"></script>
× <script src="http://www.swiper.com.cn/dist/js/swiper.min.js"></script>
× <link href="http://www.swiper.com.cn/dist/css/swiper.min.css" />