简单的HTML与vue.js无法正常工作

时间:2017-01-20 02:49:32

标签: javascript vue.js

vue.js的初学者,我跟着这个链接: https://www.sitepoint.com/getting-started-with-vue-js/

几乎将代码复制到我的html中。但是它只是不工作。有人可以帮我找到出错的地方吗?
以下是所有代码:

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

结果只是:{{name}}

1 个答案:

答案 0 :(得分:9)

您需要添加<head>标记,并在文件末尾添加脚本,如下所示:

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