如何在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 {...}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章