最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Simple html with vue.js not working - Stack Overflow

programmeradmin0浏览0评论

A beginner of vue.js and I followed this link: /

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=".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}}

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}}

Share Improve this question asked Jan 20, 2017 at 2:49 吴环宇吴环宇 4671 gold badge7 silver badges13 bronze badges 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? – jonmrich 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? – jonmrich 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
Add a comment  | 

1 Answer 1

Reset to default 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>
发布评论

评论列表(0)

  1. 暂无评论