9

A beginner of vue.js and I followed this link: https://www.sitepoint.com/getting-started-with-vue-js/

Almost copy the code into my html.However it just not working.Can someone help me find what is going wrong?
Here are all the codes:

<html>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.min.js">
</script>

<script>

var myModel = {
  name: "Ashley",
  age: 24
};

var myViewModel = new Vue({
  el: '#my_view',
  data: myModel
});

</script>
<div id="my_view">
{{ name }}
</div>
</body>
</html>

The result is just:{{name}}

5
  • I am assure that vue.js is downloaded successfully . Commented Jan 20, 2017 at 2:52
  • This is working here: jsfiddle.net/b75yspL8. What's not working for you? Commented Jan 20, 2017 at 2:53
  • @jonmrich why it is not working in my computer? I just double clicked html file and open it in chrome. Commented Jan 20, 2017 at 2:56
  • Does the jsfiddle work for you? Commented Jan 20, 2017 at 2:59
  • @jonmrich Yeah,jsfiddle works. Now the problem solved thanks to the first answer. Commented Jan 20, 2017 at 3:09

1 Answer 1

16

You need to add the <head> tag and add the script at the end of the file like this:

<html>
<head>
<title></title>
</head>
<body>
<div id="my_view">
{{ name }} {{ age }}
</div>

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

<script>

var myModel = {
  name: "Ashley",
  age: 24
};

var myViewModel = new Vue({
  el: '#my_view',
  data: myModel
});

</script>

</body>
</html>
Sign up to request clarification or add additional context in comments.

3 Comments

Is head tag really a must?
FYI: Here's a post about omitting head tags: stackoverflow.com/questions/5641997/…
Thank you sooo much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.