Vue Swiper导入swiper.css报错This dependency was not found:swiper/dist/css/swiper.css

Vue使用swiper下出错:
This dependency was not found:swiper/dist/css/swiper.css
To install it, you can run: npm install --save swiper/dist/css/swiper.css
使用npm下载了:npm install swiper vue-awesome-swiper --save
转到“ node_modules”文件夹,
找到“ vue-awesome-swiper”,
选择“ dist”
一直报错找不到此文件swiper.css。
哇~~~~~~~~~冷静!冷静让我快乐,让我们捋捋思路啊,
之前:官方推荐使用

import 'swiper/dist/css/swiper.css'
import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'

npm run serve运行后
###出错:
This dependency was not found:swiper/dist/css/swiper.css
To install it, you can run: npm install --save swiper/dist/css/swiper.css
实际上我的swiper版本是6.0.4
我当时眼睛一定是被美女吸引注意力;),没仔细看到:官方说明了Swiper安装6.0版本或以上的话需要引入另外一个css

import 'swiper/swiper-bundle.css'

替代

import 'swiper/css/swiper.css'

官网上英文原话 如下
Vue Swiper导入swiper.css报错This dependency was not found:swiper/dist/css/swiper.css_第1张图片

So改正:就改了第一行代码

import 'swiper/swiper-bundle.css'
import { Swiper, SwiperSlide, directive } from 'vue-awesome-swiper'

OK,bug排除,真妙啦!

你可能感兴趣的:(javascript,css,vue.js)