vue项目使用jquery插件

vue yekong 111℃

引入插件

import jQuery from 'jquery'
import '../utils/jquery.leoTextAnimate'

使用

for (var i = 0; i < 14; i++) {
      jQuery('.number' + i).leoTextAnimate({
        delay: 2000,
        autorun: true,
        fixed: [',', ':', '.'],
        start: '0'
      })
    }

vue.config.js配置

const webpack = require('webpack')
configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        'window.$': 'jquery',
        Popper: ['popper.js', 'default']
      })
    ]
  },

完整配置

const webpack = require('webpack')
module.exports = {
  publicPath: '',
  productionSourceMap: false,
  lintOnSave: false,
  configureWebpack: {
    plugins: [
      new webpack.ProvidePlugin({
        $: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery',
        'window.$': 'jquery',
        Popper: ['popper.js', 'default']
      })
    ]
  },
  devServer: {
    proxy: {
      '/user': {
        target: ip,
        changeOrigin: true,
        pathRewrite: {
          '^/user': '/user'
        }
      },
      '/host': {
        target: ip,
        changeOrigin: true,
        pathRewrite: {
          '^/host': '/host'
        }
      },
      '/task': {
        target: ip,
        changeOrigin: true,
        pathRewrite: {
          '^/task': '/task'
        }
      },
      '/log': {
        target: ip,
        changeOrigin: true,
        pathRewrite: {
          '^/log': '/log'
        }
      },
      '/util': {
        target: ip,
        changeOrigin: true,
        pathRewrite: {
          '^/util': '/util'
        }
      },
      '/article': {
        target: ip,
        changeOrigin: true,
        pathRewrite: {
          '^/article': '/article'
        }
      }
    }
  }
}
喜欢 (0)