I am trying to build a demo app with Vue.js. What I am getting is an odd error that Vue is not defined.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue JS Intro</title>
</head>
<body>
<div id="demo">
<p>{{message}}</p>
<input v-model="message">
</div>
<script type="JavaScript" src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>
<script>
var demo = new Vue({
el: '#demo',
data: {
message: 'Hello Vue.js!'
}
})
</script>
</body>
</html>
What did I miss here? This is not a CDN issue as I also downloaded the library from the official website, used it and got the same result
index.html:15 Uncaught ReferenceError: Vue is not defined
I got this error but as undefined due to the way I included js files
Initailly i had
in the end of my .cshtml page GOT Error Vue not Defined but later I changed it to
and magically it worked. So i assume that vue js needs to be loaded on top of the .vue
I needed to add the script below to index.html inside the HEAD tag.
But in your case, since you don't have index.html, just add it to your HEAD tag instead.
So it's like:
try to fix
type="JavaScript"
totype="text/javascript"
in you vue.js srcipt tag, or just remove it. Modern browsers will take script tag as javascript as default.Sometimes the problem may be if you
import
that like this:this may overwrite the original
Vue
reference.jsBin demo
and than
type="JavaScript"
should betype="text/javascript"
(or rather nothing at all)I found two main problems with that implementation. First, when you import the
vue.js
script you usetype="JavaScript"
ascontent-type
which is wrong. You should remove thistype
parameter because by defaultscript
tags havetext/javascript
as defaultcontent-type
. Or, just replace thetype
parameter with the correctcontent-type
which istype="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: