vue-cli使用npm安裝jquery第三方庫報404解決方案

問題描述:jquery有很多第三方庫很好用,但是在vue裏面用npm安裝時報404錯誤,於是只好把js庫放在項目中,然後手動導入。本案例要在vue-cli中引入的是face-cursor.js。

  1. 在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>
  1. 編輯jquery.js文件
import $ from 'jquery'
window.$ = $
window.jQuery = $
export default $
  1. 編輯jQuery-face-cursor.js文件:這是下載下來的插件,需要在裏面手動導入jquery並且export出去
    在這裏插入圖片描述
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章