区别
- Vue数据与视图的分离
- Vue数据驱动视图
Jquery 简单示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery</title>
</head>
<body>
<input id="title" />
<button id="add">udto list</button>
<ul id="list">
</ul>
<script type="application/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script type="application/javascript">
$('#add').click(function () {
$('#list').append('<li>'+$('#title').val()+'</li>')
$('#title').val('');
})
</script>
</body>
</html>
Vue 简单示例:
<div id="example-1">
<input v-model="title" />
<button v-on:click="add">udto list</button>
<ul>
<li v-for="item in items">
{{ item.message }}
</li>
</ul>
</div>
var example1 = new Vue({
el: '#example-1',
data: {
title:'',
items: [
{ message: 'Foo' },
{ message: 'Bar' }
]
},
methods:{
add:function(){
this.items.push({message: this.title})
this.title =''
}
}
})
Vue原理浅析请看下一篇随笔:http://www.cnblogs.com/fuGuy/p/9222249.html