简体   繁体   中英

Including bootstrap in Vue.js throwing jQuery not found error

I'm writing a chrome extension using Vue.js, for the interface I need bootstrap. I added the bootstrap like the following but it throwing the the error Uncaught ReferenceError: jQuery is not defined at Object.dismiss (popup.js:9113)

import jQuery from 'jquery';
import bootstrap from 'bootstrap';
import Vue from 'vue';
import App from '../component/app.vue';

var app=new Vue({
  el:'#app',
  data:{
    name:'vue-chrome-extension'
},
render: h =>h(App)
})

how i can fix this error?

 - First Upoll Install the Jquery Npm Package via this command where ur
   project is situated .

   open the command prompt >> enter the following Command.

   **cd "your Project folder path"**   then Press enter  Then  Type the following command to install the Jquery package in ur project. As

    @TremendusApps suggests in his answer, add the Expose Loader
   package:

   npm install expose-loader --save-dev

   import in your entry point main.js like this:

   import 'expose?$!expose?jQuery!jquery'


   Or 

   Add the ProvidePlugin to the plugins array in both
   build/webpack.dev.conf.js and build/webpack.prod.conf.js so that
   jQuery becomes globally available to all your modules:

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

Regards.

尝试全局设置window.jQuery对象

window.jQuery = jQuery;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM