第一个Vue2程序

第一个Vue2程序
  • 在文件开头引入 Vue

<script src = "../js/vue.js"></script>
  • 创建 Vue 托管的容器

<div id="app"> </div>
  • 创建 Vue 并挂载到 id 为 app 的 html 元素上

	new Vue({template : '<h1>{{msg}}</h1>',data : {msg : 'Hello World'}}).$mount('#app')
  • 完整代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"> </div>
    <script src = "../js/vue.js"></script>  <script>        new Vue({            template : '<h1>{{msg}}</h1>',            data : {                msg : 'Hello World'            }        }).$mount('#app')
    </script>
</body>
</html>
  • 运行结果