vue单页应用中如何使用jquery的方法示例

如题所述



前言

本文给大家介绍的是关于在vue单页应用中使用jquery的相关内容,主要记录一个今天用到的vue-cli建立的应用中引入jquery的方式。下面话不多说,来一起看看详细的介绍吧。

方法如下:

1.首选通过npm安装jquery


npm install jquery --save
2.在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')
}
},
...
}
3.在需要的地方

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:{
}
}
总结

温馨提示:答案为网友推荐,仅供参考