Vue中引入swiper報(bào)錯(cuò)的問題及解決
首先上報(bào)錯(cuò)信息
-----------更新-------------------------------------------
都是由于版本問題惹得鍋?。?!
剛開始我的swiper安裝的是最新版,也就是7.0的版本,但是報(bào)各種錯(cuò),我就降成了6.0的版本。
頁面是可以正常顯示出來了,但是我的swiper的options配置完全不起作用,不能自動播放,也不顯示分頁器注意。
查詢得知VUE2對于高版本的swiper可能兼容性不好,所以我卸載了6.0的版本,安裝了老版本
npm install swiper@5 vue-awesome-swiper@3 -S
但是還是報(bào)錯(cuò),錯(cuò)誤信息如下:
Cannot set property ‘params‘ of undefined
查詢得知
@3.x 版本的 ---- 引入模塊時(shí)使用小寫
import { swiper, swiperSlide } from “vue-awesome-swiper”;
@4.x 版本的 ---- 引入模塊時(shí)使用大寫
import { Swiper, SwiperSlide } from “vue-awesome-swiper”;
我改成小寫之后終于成功了,界面完好顯示
-----------更新-------------------------------------------
These dependencies were not found:
swiper in ./node_modules/vue-awesome-swiper/dist/vue-awesome-swiper.jsswiper/css/swiper.css in ./node_modules/cache-loader/dist/cjs.js??ref–12-0!./node_modules/babel-loader/lib!./node_modules/cache-loader/dist/cjs.js??ref–0-0!./node_modules/vue-loader/lib??vue-loader-options!./src/components/Banner.vue?vue&type=script&lang=js&
To install them, you can run: npm install --save swiper swiper/css/swiper.css‘
對于第二個(gè)報(bào)錯(cuò)的原因,github官網(wǎng)上已經(jīng)給出原因
https://github.com/surmon-china/vue-awesome-swiper
import Vue from 'vue' import VueAwesomeSwiper from 'vue-awesome-swiper' // import style (>= Swiper 6.x) import 'swiper/swiper-bundle.css' // import style (<= Swiper 5.x) import 'swiper/css/swiper.css' Vue.use(VueAwesomeSwiper, /* { default options with global component } */)
去到package.json里面查看安裝的swiper的版本號,為7.x版本
所以把導(dǎo)入css的代碼替換為import 'swiper/swiper-bundle.css'
對于第一個(gè)錯(cuò)誤原因,是由于swiper的版本過高問題導(dǎo)致的,卸載當(dāng)前版本:npm uninstall --save swiper
下載swiper6.x版本
npm install --save swiper@6.8.1
所有報(bào)錯(cuò)問題解決。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vite打包時(shí)去除console的方法實(shí)現(xiàn)
Vite打包項(xiàng)目時(shí),需要去除開發(fā)時(shí)加入的console、debugger調(diào)試信息,本文主要介紹了Vite打包時(shí)去除console的方法實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08Vue學(xué)習(xí)筆記進(jìn)階篇之過渡狀態(tài)詳解
本篇文章主要介紹了Vue學(xué)習(xí)筆記進(jìn)階篇之過渡狀態(tài)詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07使用electron-builder將項(xiàng)目打包成桌面程序的詳細(xì)教程
這篇文章主要介紹了使用electron-builder把web端的項(xiàng)目打包生成桌面程序,并可安裝程序,文中通過代碼示例和圖文結(jié)合的方式給大家介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下2024-08-08vue項(xiàng)目中使用tinymce編輯器的步驟詳解
本文分步驟給大家介紹了vue項(xiàng)目中使用tinymce編輯器的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-09-09vue3中的對象時(shí)為proxy對象如何獲取值(兩種方式)
使用vue3.0時(shí),因?yàn)榈讓邮鞘褂胮roxy進(jìn)行代理的所以當(dāng)我們打印一些值得時(shí)候是proxy代理之后的是Proxy<BR>對象,Proxy對象里邊的[[Target]]才是真實(shí)的對象,那么如何獲取這個(gè)值呢,下面下面給大家介紹兩種方式,感興趣的朋友一起看看吧2023-01-01