Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Fastclick on NuxtJS #606

Open
shidcordero opened this issue Aug 4, 2020 · 2 comments
Open

Fastclick on NuxtJS #606

shidcordero opened this issue Aug 4, 2020 · 2 comments

Comments

@shidcordero
Copy link

shidcordero commented Aug 4, 2020

I am trying to add this library to nuxt js.

What I have now is a file under plugins/fastclick.js

import FastClick from 'fastclick'

export default ({ document }) => {
  FastClick.attach(document.body)
}

which i use to import that one in my nuxt config using

plugins: [
    { src: '~/plugins/fastclick.js' }
  ]

but the result is I am getting ReferenceError: navigator is not defined error

I tried to provide the file using webpack.ProvidePlugin

 build: {
    plugins: [new webpack.ProvidePlugin({ FastClick: 'fastclick' })]
 }
@twinkelmann
Copy link

A plugin sounds cleaner, but as a temporary fix, here is how I implemented it in NuxtJS v2.11.0.
In layouts/default.vue, I added the following (I have a single layout, but you could do it in every layout):

import fastClick from 'fastclick'
export default {
...
  beforeMount() {
    fastClick.attach(document.body)
  },
...
}

@yeluowuhen52
Copy link

A plugin sounds cleaner, but as a temporary fix, here is how I implemented it in NuxtJS v2.11.0.
In layouts/default.vue, I added the following (I have a single layout, but you could do it in every layout):

import fastClick from 'fastclick'
export default {
...
  beforeMount() {
    fastClick.attach(document.body)
  },
...
}

Thanks,your solution is userful to me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants