I was using vue-awesome-swiper but recently I have some issues with it on mobile devices ( i have a buttons carousel and when i click on one of them it takes around a second or two for btn to be clicked ) and as that package hasn't been updated since 2020 and still using swiper v5 , I decided to use Swiper js itself . I have done as said in docs but I get dependency not found
error
package.json
{
"name": "myapp",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "nuxt",
"dev:host": "nuxt --hostname 0.0.0.0 --port 8000",
"build": "nuxt build",
"start": "nuxt start",
"generate": "nuxt generate"
},
"dependencies": {
"@nuxtjs/axios": "^5.13.6",
"@nuxtjs/device": "^2.1.0",
"core-js": "^3.15.1",
"nuxt": "^2.15.7",
"swiper": "^7.0.9",
"vuetify": "^2.5.5"
},
"devDependencies": {
"@nuxtjs/vuetify": "^1.12.1",
"@mdi/font": "^5.9.55",
"@nuxtjs/dotenv": "^1.4.1",
"noty": "^3.2.0-beta",
"nuxt-gsap-module": "^1.2.1",
"sass": "1.32.13"
}
}
test.vue
<template>
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="(item, idx) in 20" :key="item" style="width:auto">
<v-chip
class="items px-2"
:class="{'items--active': activeId === item }"
label @click.prevent="itemClicked(item, idx)">
{{item}}
</v-chip>
</div>
</div>
</div>
</template>
<script>
import Swiper , { FreeMode } from 'swiper';
import 'swiper/css';
export default {
data(){
return{
activeId: null
}
},
methods:{
itemClicked(item, itemIndex){
this.activeId = item
},
},
created(){
if(process.client){
Swiper.use([FreeMode]);
const swiper = new Swiper('.swiper', {
preventClicks: true,
preventClicksPropagation: true,
loop: false,
slidesPerView: 'auto',
spaceBetween: 30,
freeMode: {
enabled: true,
sticky: true
}
});
}
}
}
</script>
UPDATE: As suggested tried plugin injection and still get
These dependencies were not found:
* swiper in ./plugins/swip.js
* swiper/css in ./plugins/swip.js
To install them, you can run: npm install --save swiper swiper/css
plugins/swip.js
import Swiper , { FreeMode } from 'swiper';
import 'swiper/css';
export default ({ app }, inject) => {
inject('swiper', (el , options)=>{
Swiper.use([FreeMode]);
return new Swiper(el, options);
})
}