Search code examples
vue.jslocal

I want to use Vue local, but it doesnt work


I have index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script type="module">
        import Vue from '/static/js/vue.js'

        new Vue({
            el: '#index',
            data:{
                message:'Hello Vue!'
            }
        })
    </script>
    <div id="index">
        <p>{{ message }}</p>
    </div>
</body>
</html>

also I have this file structure

enter image description here

But I get this error:

GET http://localhost:8080/static/js/vue.js net::ERR_ABORTED 404

Can anybody help me? I want to use Vue.js without webpack, npm or something else.


Solution

  • Put your Vue scripts at the end of the body and as @Terry suggested change the path of your vue.js script to '/js/vue.js':

    here's a working example https://codepen.io/ellisdod/pen/PoqBRbg?editors=1010

    <body>
        <div id="index">
            <p>{{ message }}</p>
        </div>
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <script>
    
            new Vue({
                el: '#index',
                data:{
                    message:'Hello Vue!'
                }
            })
        </script>
    </body>