Vue中使用jquery:很简单

在build文件夹下的webpack.base.conf.js文件

module.exports->resolve->alias

 'jquery': path.resolve(__dirname, '../node_modules/jquery/src/jquery'),
 'directives': path.resolve(__dirname, '../src/directives'),

如图
在这里插入图片描述

虽然webpack中有默认内置jquery,但是还是要install一下

cnpm install --save jquery

然后在app.vue中引入

import jQuery from 'jquery'

就可以使用了,如

mounted(){
    this.city()
    $(()=>{
      $(".swiper").click(function(e){
          console.log(e.target)
      })
    })
  }
发布了33 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_22188085/article/details/87919918