alvarotrigo / vue-fullpage.js

Official Vue.js wrapper for fullPage.js http://alvarotrigo.com/vue-fullpage/
GNU General Public License v3.0
1.86k stars 255 forks source link

Error in mounted hook: "ReferenceError: $ is not defined" #28

Closed ekoeditaa closed 6 years ago

ekoeditaa commented 6 years ago

The plugin fullpage.js is not initialized because of this error. I have followed the instructions from the readme and some past issues, following the examples but still can't work.

Here are my imports in index.html

<head>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.5.2/animate.min.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp"
    crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.5/jquery.fullpage.min.css">
</head>

<body style="margin: auto;">
  <div id=app></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.5/jquery.fullpage.min.js"></script>
<script type="text/javascript" src="build.js"></script>

Here is my usage, in a single component file, following the tutorial.

<template>
  <div>
    <full-page :options="options">
      <div class="section">
        First section ...
      </div>
      <div class="section">
        Second section ...
      </div>
    </full-page>
  </div>
</template>

<script>
  import fullPage from 'vue-fullpage.js';

  export default {
    components: {
      fullPage,
    },

    data() {
      return {
        options: {
          paddingTop: '30px'
        },
      }
    },
  }
</script>

This are my dependencies in package.json

"dependencies": {
    "animate.css": "^3.6.1",
    "animated-vue": "^0.5.3",
    "fullpage.js": "^2.9.7",
    "vue": "^2.5.2",
    "vue-fullpage.js": "0.0.1",
    "vue-quick-menu": "^1.0.7",
    "vue-router": "^3.0.1",
    "vue-typer": "^1.2.0",
    "vue2-animate": "^2.0.0",
    "jquery": ">=1.6.0"
  },
  "devDependencies": {
    "autoprefixer": "^7.1.2",
    "babel-core": "^6.22.1",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-loader": "^7.1.1",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.22.0",
    "babel-plugin-transform-vue-jsx": "^3.5.0",
    "babel-preset-env": "^1.3.2",
    "babel-preset-stage-2": "^6.22.0",
    "chalk": "^2.0.1",
    "copy-webpack-plugin": "^4.0.1",
    "css-loader": "^0.28.0",
    "extract-text-webpack-plugin": "^3.0.0",
    "file-loader": "^1.1.4",
    "friendly-errors-webpack-plugin": "^1.6.1",
    "html-webpack-plugin": "^2.30.1",
    "node-notifier": "^5.1.2",
    "node-sass": "^4.9.0",
    "optimize-css-assets-webpack-plugin": "^3.2.0",
    "ora": "^1.2.0",
    "portfinder": "^1.0.13",
    "postcss-import": "^11.0.0",
    "postcss-loader": "^2.0.8",
    "postcss-url": "^7.2.1",
    "rimraf": "^2.6.0",
    "sass-loader": "^7.0.3",
    "semver": "^5.3.0",
    "shelljs": "^0.7.6",
    "style-loader": "^0.21.0",
    "uglifyjs-webpack-plugin": "^1.1.1",
    "url-loader": "^0.5.8",
    "vue-loader": "^13.3.0",
    "vue-particles": "^1.0.9",
    "vue-style-loader": "^3.0.1",
    "vue-template-compiler": "^2.5.2",
    "webpack": "^3.6.0",
    "webpack-bundle-analyzer": "^2.9.0",
    "webpack-dev-server": "^2.9.1",
    "webpack-merge": "^4.1.0"
  },
  "engines": {
    "node": ">= 6.0.0",
    "npm": ">= 3.0.0"
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not ie <= 8"
  ]

And lastly, this is vue.config.js

const webpack = require('webpack');

module.exports = {
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery'
      })
    ]
  }
}

I am using vue-cli webpack for this project. Did I miss any steps in the setup? Why is the cause of the error? Thanks.

ekoeditaa commented 6 years ago

I actually solved this problem by moving the script imports to the inside the head tag. Thank you.

alvarotrigo commented 6 years ago

:) glad you solved it! I'm about to release a new version soon, so hope some of these problems go away with it!

ekoeditaa commented 6 years ago

Do you have any idea why is it wrong previously? I want to understand more about it. Thank you for the great work, really appreciate it!

alvarotrigo commented 6 years ago

No sure. Don't have much time to look at it now, so if it doesn't happen anymore on the new version that I'll be releasing soon, i guess there's no point on looking it up :)

ekoeditaa commented 6 years ago

Okay then, thank you for the hard work again! :)

jinze commented 6 years ago

I hope there is a new release version A.S.A.P.

alvarotrigo commented 6 years ago

Yeap, in less than 3 weeks for sure. Hope for 1 week!