問題描述:jquery有很多第三方庫很好用,但是在vue裏面用npm安裝時報404錯誤,於是只好把js庫放在項目中,然後手動導入。本案例要在vue-cli中引入的是face-cursor.js。
- 在Test.vue中導入jquery和jQuery-face-cursor.js插件,如下:
<template>
<div class="card">
<h2>More content</h2>
<p>......</p>
</div>
</template>
<script>
import ('../assets/js/jQuery-face-cursor.js');//要引入的第三方插件
import $ from '../assets/js/jquery.js';//把jquery引入
export default {
name: "Test",
mounted(){
this.init();
},
methods:{
init(){
$(".card").faceCursor();
},
}
}
</script>
<style scoped>
.card {
background: #fff;
display: inline-block;
margin: 4em;
box-shadow: .5em 0 1.25em #ccc;
border-radius: .3em;
overflow: hidden;
max-width: 20em;
}
</style>
- 編輯jquery.js文件
import $ from 'jquery'
window.$ = $
window.jQuery = $
export default $
- 編輯jQuery-face-cursor.js文件:這是下載下來的插件,需要在裏面手動導入jquery並且export出去