<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<!--
1、仅仅只需要关注数据、业务逻辑和事件,dom直接的操作隐藏起来,不用再重复去做这个事情。
2、大大增加团队效率,团队协作能力
3、模块化,降低耦合度
4、数据的双向绑定,视图和模型的数据是绑定在一起的,变更1个,那么所有都变更
--> <!--视图-->
<div id="app">
<h1>{{jsonMsg}}</h1>
<p>{{jsonContent}}</p>
<h1> 这是H1内容: {{ isA ? a : b}}</h1> <!--将变量绑定到属性上-->
<a v-bind:href="httpUrl">链接地址</a>
<a :href="httpUrl">链接地址</a> <div>
{{htmlElement}}
</div> <div v-html='htmlElement'></div> <h1>{{msg}}</h1>
<h1 v-once>{{msg}}</h1>
<input type="text" v-model='msg' name="" id="" value="" /> <button v-on:click='changeUrl'>更改为淘宝地址</button>
<!--
v-on:可以缩写成@
-->
<button @click='changeMsg'>更改msg</button>
</div>
<!--
vue模板:
1、变量放在{{}}里面,里面可以正常运行JS表达式
2、变量如果要放在HTML的属性里面,那么就需要使用v-bind,缩写即前面加冒号
3、默认是将HTML以字符串的形式输出到视图,如果想要以HTML的形式输出到视图,那么需要使用v-html这个指令
4、v-once只渲染1次
5、绑定事件的书写方式:v-on, vue应用生命周期(即执行过程)
new Vue(配置变量)
---》初始化
---》beforecreate
---》created
--》beforeMount(渲染之前、挂载之前)
---》mounted
--》beforeupdate
---》updated
---》beforeDestory
---》destoryed 条件渲染: -->
<script type="text/javascript">
var obj = {
el:'#app',
data:{
msg:'helloworld',
num:'123456778',
isA:false,
a:8,
b:4,
httpUrl:'http://www.baidu.com',
htmlElement:'<button>这是一个按钮</button>',
jsonMsg:'',
jsonContent:''
},
methods:{
changeMsg:function(){
this.msg = '今天天气不错'
},
changeUrl:function(){
this.httpUrl = 'http://www.taobao.com'
}
},
beforeCreate:function(){
console.log('创造之前执行的函数')
},
created:function(){
console.log('创造之后')
},
beforeMount:function(){
console.log('挂载之前')
var that = this
$.ajax({
url:'abc.json',
success:function(res){
console.log(res)
that.jsonMsg = res.msg
that.jsonContent = res.content
}
})
},
mounted:function(){
console.log('挂载之后')
},
beforeUpdate:function(){
console.log('更新之前')
},
updated:function(){
console.log('更新之后')
}
}
var app = new Vue(obj)
console.log(app) </script>
</body>
</html>

最新文章

  1. ORACLE 实例及RAC
  2. 学习从零开始写jQuery框架
  3. ajax 清除缓存
  4. mongdb创建自增主键(primary key)的相关讨论 - Jason.Zhi
  5. Linux之sed,awk(流编辑器)
  6. poj 2373 单调队列优化背包
  7. Linux下crontab命令详解
  8. python学习笔记--Django入门三 Django 与数据库的交互:数据建模
  9. Java环境的安装与配置
  10. motan源码分析三:与spring框架的结合
  11. 【初级坑跳跳跳】[NULLException] findViewById() id 引用错误,导致空指针
  12. MYSQL PGA SGA设置
  13. dict-字典功能介绍
  14. SVM:根据大量图片来精确实现人脸识别—Jason niu
  15. java模板设计模式
  16. gitea 源码阅读笔记 002 生成无依赖单文件可执行包
  17. 【BZOJ3676】 [Apio2014]回文串(SAM,manacher)
  18. Office2016自定义安装
  19. &lt;构建之法&gt;阅读笔记6
  20. 微软职位内部推荐-Senior Software Development Engineer_Commerce

热门文章

  1. DataFrame 转换为Dataset
  2. 检查图片是否损坏、图片后缀是否与实际图片类型对应 - Python
  3. SPSS基础学习方差分析—单因素分析
  4. 一个低级错误引发Netty编码解码中文异常
  5. mysql uuid使用
  6. Mac OS Catalina 如何删除自带的应用
  7. Http协议Content-Length详解
  8. Mysql高手系列 - 第24篇:如何正确的使用索引?【高手进阶】
  9. 02-23 决策树CART算法
  10. UVA - 1160 X-Plosives