vue bootstrap小例子一枚
vue和angular非常像都是MVVM。道理都是想通的,就是語法的差異
我覺得vue和angular區(qū)別:
1.vue更輕,更便捷,適用于移動(dòng)開發(fā)
2.vue更簡單。。
angular和vue指令的差別大致就是 ng-xxx和v-xxx。
vue是用過new Vue創(chuàng)建實(shí)例,然后在屬性data綁定數(shù)據(jù),在屬性methods里添加方法。
vue的循環(huán)遍歷是 v-for=“” ,事件是 v-on:clicl =“”;
直接上代碼。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="bootstrap.css" rel="external nofollow" >
<style>
tr{
vertical-align: inherit;
}
</style>
<script src="jquery.js"></script>
<script src="bootstrap.js"></script>
<script src="node_modules/vue/dist/vue.js"></script>
<script>
window.onload= function(){
var vm = new Vue({
el:'.container',
data:{
myData:[],
username:'',
age:''
},
methods:{
add:function(){
this.myData.push({
name:this.username,
age:this.age
});
this.username="";
this.age="";
},
reset:function(){
this.username="";
this.age="";
},
del:function(index){
this.myData.splice(index,1)
},
delAll:function(){
this.myData=[];
}
}
})
}
</script>
</head>
<body>
<div class="container">
<form role="form">
<div class="form-group">
<label for="username">用戶名:</label>
<input placeholder="輸入用戶名" type="text"
v-model="username"
id="username" class="form-control">
</div>
<div class="form-group">
<label for="age">年齡:</label>
<input placeholder="輸入年齡" type="text"
v-model="age"
id="age" class="form-control">
</div>
<div class="form-group">
<input type="button" class="btn btn-info" v-on:click="add()" value="添加">
<input type="button" class="btn btn-info" v-on:click="reset()" value="重置">
</div>
</form>
<hr>
<table class="table table-bordered table-hover">
<caption>用戶信息表</caption>
<tr class="text-danger">
<td class="text-center">序號</td>
<td class="text-center">名字</td>
<td class="text-center">年齡</td>
<td class="text-center">操作</td>
</tr>
<tr v-for="(item,index) in myData">
<td class="text-center">{{index+1}}</td>
<td class="text-center">{{item.name}}</td>
<td class="text-center">{{item.age}}</td>
<td class="text-center">
<button class="btn btn-danger btn-sm"
v-on:click="del(index)"
data-toggle="dialog" data-target="#layer"
>刪除</button>
</td>
</tr>
<tr v-show="myData.length!=0">
<td colspan="4" class="text-right">
<button v-on:click="delAll()" class="btn btn-danger btn-sm">刪除全部</button>
</td>
</tr>
<tr v-show="myData.length==0">
<td colspan="4" class="text-center">
<p>暫無數(shù)據(jù)</p>
</td>
</tr>
</table>
</div>
</body>
</html>
效果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Layui Form 自定義驗(yàn)證的實(shí)例代碼
今天小編就為大家分享一篇Layui Form 自定義驗(yàn)證的實(shí)例代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09
利用函數(shù)的惰性載入提高javascript代碼執(zhí)行效率
在 addEvent 函數(shù)每次調(diào)用的時(shí)候都要走一遍,如果瀏覽器支持其中的一種方法,那么他就會(huì)一直支持了,就沒有必要再進(jìn)行其他分支的檢測了2014-05-05
cropper.js和exif.js實(shí)現(xiàn)頭像上傳縮放裁剪旋轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了cropper.js和exif.js實(shí)現(xiàn)頭像上傳縮放裁剪旋轉(zhuǎn),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
js中substring和substr的詳細(xì)介紹與用法
這篇文章介紹了js中substring和substr的用法,有需要的朋友可以參考一下2013-08-08
在javascript中隨機(jī)數(shù) math random如何生成指定范圍數(shù)值的隨機(jī)數(shù)
本篇文章給大家介紹在javascript中隨機(jī)數(shù)math random如何生成指定范圍數(shù)值的隨機(jī)數(shù),由于math.random生成了一個(gè)偽隨機(jī)數(shù),之后還要經(jīng)過我們的后期處理。對隨機(jī)數(shù)math random感興趣的朋友一起了解了解吧2015-10-10
JavaScript語言精粹經(jīng)典實(shí)例(整理篇)
本文是小編日常讀書筆記整理有關(guān)javascript知識,都是js精粹非常不錯(cuò),具有參考借鑒價(jià)值,特此分享到腳本之家平臺供大家參考2016-06-06
只需五句話搞定JavaScript作用域(經(jīng)典)
javascript作用域是前端開發(fā)比較難理解的知識點(diǎn),下面小編給大家提供五句話幫助大家很快的了解js作用域,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起學(xué)習(xí)吧2016-07-07

