我們測試使用App.vue頁面
一.先把js文件放到項目中
二.引入jquery文件
在<script>...</script>代碼段中引入,放置在頭部(注意import后面有一個空格)
import '../utils/niuniu/jquery-1.6.4.min.js'
注意,如果不加 /* eslint-disable*/ ,那么在開啟ESLint時,會報以下錯誤信息,加上則可以免除驗證
三.編寫文件,測試jquery
文件完整信息如下
<template>
<div id="app">
<img src="./assets/logo.png"><br/>
<input type="text" name="user" id="user" placeholder="請輸入信息" /><br/>
<span id="msg"></span>
<!-- <router-view/> -->
</div>
</template>
<script>
/* eslint-disable*/
import '../utils/niuniu/jquery-1.6.4.min.js'
import { Script } from 'vm';
export default {
name: 'App',
created () {
console.log($('#user'))
}
}
$(function() {
// 綁定jquery處理事件,動態監聽文本框內容變化
$('#user').bind("input propertychange",function(event){
$('#msg').html('文本框里的內容是:' + this.value)
})
})
</script>
<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
查看效果,文本框輸入內容,可實時顯示出輸入的信息,說明jquery引用成功:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。