【问题标题】:Including bootstrap in Vue.js throwing jQuery not found error在 Vue.js 中包含引导程序会引发 jQuery not found 错误
【发布时间】:2017-12-01 11:50:24
【问题描述】:

我正在使用 Vue.js 编写一个 chrome 扩展,用于我需要引导的界面。我添加了如下的引导程序,但它抛出了错误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)
})

我该如何解决这个错误?

【问题讨论】:

  • 你尝试了什么?您检查导入是否正确定向?
  • @YorkiBonilla - 我是 Vue.js 的新手。我使用 npm 命令安装引导程序并使用 import bootstrap from 'bootstrap'; 导入

标签: javascript google-chrome-extension webpack vue.js gulp


【解决方案1】:
 - 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.

【讨论】:

  • npm install expose-loader --save-devimport 'expose?$!expose?jQuery!jquery' 为我工作。谢谢!
【解决方案2】:

尝试全局设置window.jQuery对象

window.jQuery = jQuery;

【讨论】:

    猜你喜欢
    • 2017-11-18
    • 2015-11-13
    • 1970-01-01
    • 2013-02-20
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    相关资源
    最近更新 更多