Vue基础02Hello Vue
创建第一个Vue程序并理解Vue的设计思想
1 创建Vue程序
要求:创建一个index.html页面,页面显示“hello world” 一秒钟之后变为"hello vue"
小技巧:
- 输入!按回车,可快速创建html结构
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 宿主文件 -->
<div id="app">
{{title}}
</div>
<script src="../js/vue.js"></script>
<script>
// 1.创建vue实例,参数为配置对象
const app = new Vue({
// 指明宿主文件
el: '#app',
// 数据
data() {
return {
title: "hello html"
}
},
})
// 响应式数据
setTimeout(() => {
app.title = 'hello vue'
}, 1000);
</script>
</body>
</html>
2 理解Vue的设计思想
2.1 Vue设计思想
-
数据驱动应用
-
MVVM模式的践行者
-
Vue是一个中间层,连接数据与视图
2.2 MVVM框架的三要素
- 响应式:Vue如何监听数据变化?
- 模板引擎:Vue的模板如何编写和解析?
- 渲染:Vue如何将模板转换为HTML?