如何在Vue中使用jQuery

安装依赖

yarn add jquery

修改build/webpack.base.conf.js

添加如下配置:

var webpack=require('webpack');

module.exports={} 添加如下配置:

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

在main.js中引入

import $ from 'jquery'

在Vue组件中的script块中使用

// 这是jq的代码
$(function(){
    $('.aui-content-main .aui-content-menu').hover(function(){
      $(this).addClass('active').find('s').hide();
      $(this).find('.aui-content-menu-dow').show();
    },function(){
      $(this).removeClass('active').find('s').show();
      $(this).find('.aui-content-menu-dow').hide();
    });
  });

// 这是vue的js代码
export default {...}

猜你喜欢

转载自blog.51cto.com/xvjunjie/2399214