在使用vue框架開發的時候 ,是非常的方便的,但是在工作中 ,還是會有遇到對接jq的部分的接口,這個時候就需要在vue的界面裏面引入jQuery並使用了
1:在項目裏面安裝
npm install jquery --save
2:在項目裏面找到.eslintrc.js文件打開並進行配置
我們在env中配置 jQuery:true
3.打開項目的根目錄vue.config.js文件
4:在main.js文件中導入jquery
//引入jquery
import jquery from 'jquery'
5:使用案例
使用jquery寫一個點擊事件
test.vue
<template>
<div class="test">
<div class="click">點我</div>
</div>
</template>
<script>
export default {
name: "test",
date() {
return {};
},
mounted() {
this.text();
},
methods: {
text() {
$(".click").click(function () {
alert(1);
});
},
},
};
</script>
<style >
</style>
點擊按鈕出現alert彈框