一、初始Vue
<!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>初始vue</title>
<script type="text/javascript" src="../图片素材/vue.js"></script>
</head>
<body>
<!-- 准备好一个容器 -->
<div id="root">
<!-- 用花括号来分割 -->
<h1>Hello,{{name}}</h1>
<h1>Hello,{{age}} ,{{Date.now()}}</h1>
<button>点我更换学校名字</button>
</div>
<script>
Vue.config.productionTip=false //关闭提示
//创建Vue实例
const x = new Vue({
el:'#root', //el用于指定当前Vue实例为哪个容器服务,值为css选择器字符串 document.getElementById('root')
data:{//data中用于存储数据,数据供el所指定的容器去使用。
name:"尚硅谷",
age:18
}
})
</script>
</body>
</html>
二、理解MVVM模型
<!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>
<script src="../图片素材/vue.js"></script>
</head>
<body>
<div id="root">
<h1>学校名称:{{name}}</h1>
<h1>学校地址: {{address}}</h1>
<h1>地址: {{_c}}</h1>
</div>
</body>
<script>
Vue.config.productionTip=false//阻止vue在启动时生成生产提示
var vm=new Vue({
el:'#root',
data:{
name:'尚硅谷',
address:"北京"
}
})
console.log(vm);
</script>
</html>
三、Vue模板语法
<!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>
<script src="../图片素材/vue.js"></script>
</head>
<body>
<div id="root">
<h1>插值语法</h1>
<h3>你好,{{name}}</h3>
<h1>指令语法</h1>
<!-- v-bind:动态绑定值 当成js来使用 或者简写为 :href="xxx",同样要写JS表达式,且可以直接读取到data中的所有属性
Vue中有很多的指令,且形式都是:v-???,此处我们只是拿v-bind举个例子。
-->
<a v-bind:href="school.url" v-bind:x="hello">点{{school.name}}去尚硅谷学习1</a>
<a :href="school.url">点我去{{name}}学习2</a>
<hr/>
</div>
</body>
<script>
Vue.config.productionTip=false//阻止vue在启动时生成生产提示
new Vue({
el:'#root',
data:{
name:'尚硅谷',
school:{
name:'jack',
url:"http://www.atguigu.com",
hello:"已检查"
}
}
})
</script>
</html>