M
M
Martovitskiy2017-10-22 18:55:41
JavaScript
Martovitskiy, 2017-10-22 18:55:41

How to run plugin if width > 768px?

Please help. It is necessary to run the plugin only if the user's screen width is more than 768px.

nuxt.config.js

module.exports = {
  plugins: {
     { src: '~plugins/fullpage-vue.js', ssr: false }
  },
  build: {
    vendor: [
      'axios',
      'fullpage-vue'
    ]
  }

fullpage.js
import Vue from 'vue'
import VueFullpage from 'fullpage-vue'

if (window.screen.availWidth >= 768) {
  Vue.use(VueFullpage)
}

That doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Velko, 2017-10-22
@Martovitskiy

Do you even understand that if your site is viewed from the most ordinary iPad, then it will be enough to turn it into portrait mode and that's it, your site will break?
To do Vue.use()depending on the width of the screen is a crutch. In any case, you must connect the plugin, and only then manage its initialization and destruction of the instance in some separate function that you tie to the resizeevent.
PS Screen width, if anything, window.innerWidth.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question