如何在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 {...}