question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use SSR without nuxt?

See original GitHub issue

I’m converting my project into SSR. Now i’m confused how to use vue-awesome-swiper without using Nuxt.js. I’m getting ‘Failed to resolve directive: swiper’ error even by using the following code(inside app.js).

if (process.BROWSER_BUILD) {
  const VueAwesomeSwiper = require('vue-awesome-swiper/dist/ssr')
  Vue.use(VueAwesomeSwiper)
}

Actually I’m facing another problem with third-party plugins which use window and I get windows is undefined. Plugins like : labelauty - jquery-nice-select - etc

How can I use this plugins? There should be a way to run call them in client side !? Can anyone help me with a complete solution?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

10reactions
AlbertKnagcommented, Jul 18, 2019

对于这个问题折腾了不少时间,分享出来 like this

<template>
  <section class="qk-banner">
<!--    <swiper :options="swiperOption" style="border-radius:.08rem;">-->
<!--      <swiper-slide v-for="(item, index) in data" :key="index">-->
<!--        <img :src="item.imgUrl" @click="jump(item)">-->
<!--      </swiper-slide>-->
<!--      <div class="swiper-pagination" slot="pagination" style="bottom: .08rem" v-if="data.length>1"></div>-->
<!--    </swiper>-->
    <div v-swiper:mySwiper="swiperOption">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="(item, index) in data" :key="index">
          <img :src="item.imgUrl" @click="jump(item)">
        </div>
      </div>
      <div class="swiper-pagination" slot="pagination" style="bottom: .08rem" v-if="data.length>1"></div>
    </div>
  </section>
</template>
import Vue from 'vue'
import utils from '../../utils/utils'

export default {
  name: 'Banner',
  props: {
    data: {
      type: Array,
      default () {
        let imgUrl = require('./imgs/banner.png')
        let jumpUrl = 'https://jiazheng.daojia.com/clean/h5/cleanIndex'
        return [
          {
            imgUrl: imgUrl,     // banner图片地址
            jumpUrl: jumpUrl,   // 跳转地址
            trackParam: null    // 埋点数据
          },
          {
            imgUrl: imgUrl,
            jumpUrl: jumpUrl,
            trackParam: null
          },
          {
            imgUrl: imgUrl,
            jumpUrl: jumpUrl,
            trackParam: null
          }
        ]
      }
    }
  },
  data () {
    return {
      swiperOption: {
        autoplay: {
          delay: 3000,
          disableOnInteraction: false
        },
        lazy: {
          loadPrevNext: true
        },
        pagination: {
          el: '.swiper-pagination',
          bulletClass: 'qk-banner-bullet',
          bulletActiveClass: 'qk-banner-active-bullet'
        }
      }
    }
  },
  beforeMount () {
    if (process.browser) {
      require('swiper/dist/css/swiper.css')
      const VueAwesomeSwiper = require('vue-awesome-swiper/dist/ssr')
      Vue.use(VueAwesomeSwiper)
    }
  },
  methods: {
    jump (item) {
      utils.jump(item.jumpUrl, item.trackParam)
    }
  },
  components: {
    // swiper,
    // swiperSlide
  }
}
1reaction
lichunshancommented, Jul 20, 2020
  • “swiper”: “^6.0.4”,
  • “vue-awesome-swiper”: “^4.1.1”

i use Custom Build with Swiper solved this problemhttps://www.npmjs.com/package/vue-awesome-swiper#custom-build-with-swiper

import Vue from 'vue'
import { Swiper as SwiperClass, Pagination, Mousewheel, Autoplay } from 'swiper/swiper.esm'
import getAwesomeSwiper from 'vue-awesome-swiper/dist/exporter'
SwiperClass.use([Pagination, Mousewheel, Autoplay])
Vue.use(getAwesomeSwiper(SwiperClass))
const { Swiper, SwiperSlide } = getAwesomeSwiper(SwiperClass)
import 'swiper/swiper-bundle.css'

Finally don’t forget to import the style!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server Side Rendering - Nuxt
Server-side rendering (SSR), is the ability of an application to contribute by displaying the web-page on the server instead of rendering it in...
Read more >
How can I turn off SSR for only certain pages in Nuxt.js to use ...
I want to develop an application with Nuxt.js that uses SSR for only certain pages (like artist page user page), so the pages...
Read more >
Is it possible to use Nuxt without SSR? #931 - GitHub
I would like to use Nuxt without SSR. I am not talking about nuxt generate because it does not support dynamic params in...
Read more >
Server-Side Rendering (SSR) - Vue.js
Nuxt is a higher-level framework built on top of the Vue ecosystem which provides a streamlined development experience for writing universal Vue applications....
Read more >
Nuxt.js — Best practices for client-side-only contents (client ...
Not all third party components support server side rendering (SSR). Nuxt.js provides a way for you to exclude those components from the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found