Nuxt.js: how to new a Obj from static js file not import

Created on 1 Aug 2017  Â·  8Comments  Â·  Source: nuxt/nuxt.js

I add a swiper.min.js as the doc How to use external resources? and i need new a swiper obj (simply the code ) like below :

 export default {
head: {
      script: [
        { src: '/swiper/swiper.min.js' }
      ],
      link: [
        { rel: 'stylesheet', href: '/swiper/swiper.min.css' }
      ]
    },
  mounted () {
       // simply the code
        new Swiper('.swiper-container', {
          pagination: '.swiper-pagination',
          loop: true
        })
    },
}

then the console show error like this:
image

why can't i use import the swiper file please check #1250
thank for some one to solve my problem :)

This question is available on Nuxt.js community (#c1108)

All 8 comments

This is not related to Nuxt.
This is "How do es6 imports work ?", and "How do Vuejs single file components work ?".

https://vuejs.org/v2/guide/single-file-components.html
https://stackoverflow.com/questions/35541864/es6-export-default-function

@mingliao For using swiper with Nuxt and SSR, you may try vue-awesome-swiper as a Nuxt plugin.

@pi0 @benfavre ok,thank you and i have a question. if i have a global js file in clientside like jquery or jquery plugin and the file is not a common.js module, i could include it as a static file in head config i mention in my issue, but how did i what to use the function or property in these not commonjs file ?

You can expose global functions using window. Usually libraries do this them self. So for example jquery is available using window.$ if is added to head. BTW try to rethink about your libraries, having jquery with vue is not a good idea.

@mingliao Think you need to do a bit of reading about VueJS, Webpack and Nuxt.
https://nuxtjs.org/faq/webpack-plugins

@pi0 thank you o(^▽^)o ,as you mention above, I solve my problem . and i will try your idea code without jquery .

@benfavre thank you very much,and i will read the page you mention .

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattdharmon picture mattdharmon  Â·  3Comments

vadimsg picture vadimsg  Â·  3Comments

surmon-china picture surmon-china  Â·  3Comments

pehbehbeh picture pehbehbeh  Â·  3Comments

mikekidder picture mikekidder  Â·  3Comments