记录一个今天用到的 vue-cli 建立的应用中引入 jQuery 的方式.
首选通过 NPM 安装 jQuery
NPM install jQuery --save
在 build/webpack.base.conf 文件当中引入 jQuery
- module.exports = {
- ...
- resolve: {
- extensions: ['.js', '.vue', '.json'],
- alias: {
- 'vue$': 'vue/dist/vue.esm.js',
- '@': resolve('src'),
- 'jquery': path.resolve(__dirname, '../node_modules/jquery/src/jquery')
- }
- },
- ...
- }
. 在需要的地方
- import $ from 'jquery'
- export default {
- name: 'hello',
- data () {
- return {
- msg: 'Welcome to Your vue.js App'
- }
- },
- mounted:function(){
- let test = $('#test').text()
- console.log(test)
- },
- methods:{
- }
- }// 介绍一个全栈开发交流学习圈, 欢迎加入 Q 群: 864305860
来源: http://www.qdfuns.com/article/51117/522ccf3437e2dcc64ffb967b6c19a2cf.html