npm install jquery --save

vue-cli3 配置;
在vue.config.js中

module.exports = {
  // 基本路径
  baseUrl: './',

  configureWebpack: {
	plugins: [
	  new webpack.ProvidePlugin({
		$:"jquery",
		jQuery:"jquery",
		"windows.jQuery":"jquery"
	  })
	]
  },

  lintOnSave: undefined
}

3以下的配置
webpack.base.conf.js

var webpack = require('webpack')
const ProvidePlugin = new webpack.ProvidePlugin({//引入外部类库
  $: 'jquery',
  jQuery: 'jquery',
});
module.exports = {
...
plugins: [
    ProvidePlugin,
  ],
...
}

import $ from 'jquery'
Logo

前往低代码交流专区

更多推荐