Skip to content Skip to sidebar Skip to footer

Vue Is Not Defined

I am trying to build a demo app with Vue.js. What I am getting is an odd error that Vue is not defined.

Solution 1:

jsBin demo

  1. You missed the order, first goes:

<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>

and then:

<script>var demo = newVue({
        el: '#demo',
        data: {
            message: 'Hello Vue.js!'
        }
    });
</script>
  1. And type="JavaScript" should be type="text/javascript" (or rather nothing at all)

Solution 2:

Sometimes the problem may be if you import that like this:

constVue = window.vue;

this may overwrite the original Vue reference.

Solution 3:

try to fix type="JavaScript" to type="text/javascript" in you vue.js srcipt tag, or just remove it. Modern browsers will take script tag as javascript as default.

Solution 4:

I got this error but as undefined due to the way I included js files

Initailly i had

<scriptsrc="~/vue/blade-account-update-credit-card-vue.js"asp-append-version="true"></script><scriptsrc="~/lib/vue/vue_v2.5.16.js"></script>

in the end of my .cshtml page GOT Error Vue not Defined but later I changed it to

<scriptsrc="~/lib/vue/vue_v2.5.16.js"></script><scriptsrc="~/vue/blade-account-update-credit-card-vue.js"asp-append-version="true"></script>

and magically it worked. So i assume that vue js needs to be loaded on top of the .vue

Solution 5:

I found two main problems with that implementation. First, when you import the vue.js script you use type="JavaScript" as content-type which is wrong. You should remove this type parameter because by default script tags have text/javascript as default content-type. Or, just replace the type parameter with the correct content-type which is type="text/javascript".

The second problem is that your script is embedded in the same HTML file means that it may be triggered first and probably the vue.js file was not loaded yet. You can fix this using a jQuery snippet $(function(){ /* ... */ }); or adding a javascript function as shown in this example:

// Verifies if the document is readyfunctionready(f) {
  /in/.test(document.readyState) ? setTimeout('ready(' + f + ')', 9) : f();
}

ready(function() {
  var demo = newVue({
    el: '#demo',
    data: {
      message: 'Hello Vue.js!'
    }
  })
});
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script><divid="demo"><p>{{message}}</p><inputv-model="message"></div>

Post a Comment for "Vue Is Not Defined"