vue實(shí)現(xiàn)簡單學(xué)生信息管理
本文實(shí)例為大家分享了vue實(shí)現(xiàn)學(xué)生信息管理的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>學(xué)生信息管理</title>
<link rel="stylesheet" href="./lib/bootstrap.css" >
<script src="./lib/vue.js"></script>
<style type="text/css">
#app{
margin: 10px;
}
</style>
</head>
<body>
<div id="app">
<form class="form-inline">
<div class="form-group">
<label>學(xué)號:</label>
<input type="text" class="form-control" v-model="stuNo">
</div>
<div class="form-group">
<label>姓名:</label>
<input type="email" class="form-control" v-model="name" @keyup.enter="add">
</div>
<input type="button" class="btn btn-primary" value="添加" @click="add">
<div class="form-group">
<label>搜索姓名關(guān)鍵字:</label>
<input type="email" class="form-control" v-model="keywords" @keyup.enter="search(keywords)" v-focus>
</div>
</form>
<br/>
<table class="table table-bordered" >
<thead>
<th>學(xué)號</th>
<th>姓名</th>
<th>添加時(shí)間</th>
<th>操作</th>
</thead>
<tbody v-for="(item,i) in search(keywords)" :key="item.stuNo" >
<tr>
<td>{{item.stuNo}}</td>
<td>{{item.name}}</td>
<td>{{item.cTime | dateFormat}}</td>
<td><a href="" @click.prevent=" del(item.stuNo)">刪除</a></td>
</tr>
</tbody>
</table>
</div>
<script>
// 自定義自動獲取焦點(diǎn)的全局指令
Vue.directive('focus',{
// 當(dāng)被綁定的元素插入到 DOM 中時(shí)……
inserted: function (el) {
// 聚焦元素
el.focus()
}
})
var vm = new Vue({
el:'#app',
data:{
stuNo:'',
name:'',
keywords:'',
list:[
{
stuNo:1710204016,
name:'劉小紅',
cTime:new Date()
},
{
stuNo:1710204007,
name:'李大明',
cTime:new Date()
}
]
},
methods:{
add(){
var newInfo = {stuNo:this.stuNo, name:this.name, cTime:new Date()}
this.list.push(newInfo)
this.stuNo=this.name=''
},
del(stuNo){
this.list.some((item,i)=>{
if(item.stuNo===stuNo){
this.list.splice(i,1)
return true;
}
})
},
search(keywords){
// var newList = []
// this.list.forEach(item=>{
// if(item.name.indexOf(keywords)!=-1){
// newList.push(item)
// }
// })
// return newList
return this.list.filter(item=>{
if(item.name.includes(keywords)){
return item
}
})
}
},
filters:{
dateFormat:function(dateStr){
var year = dateStr.getFullYear()
var mouth = (dateStr.getMonth() + 1).toString().padStart(2,'0')
var date = (dateStr.getDate()).toString().padStart(2,'0')
var h = (dateStr.getHours()).toString().padStart(2,'0')
var m = (dateStr.getMinutes()).toString().padStart(2,'0')
var s = (dateStr.getSeconds()).toString().padStart(2,'0')
return `${year}-${mouth}-${date} ${h}:${m}:${s}`
}
}
})
</script>
</body>
</html>
更多文章可以點(diǎn)擊《Vue.js前端組件學(xué)習(xí)教程》學(xué)習(xí)閱讀。
關(guān)于vue.js組件的教程,請大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請閱讀專題《vue實(shí)戰(zhàn)教程》
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)手機(jī)號碼的校驗(yàn)實(shí)例代碼(防抖函數(shù)的應(yīng)用場景)
這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)手機(jī)號碼的校驗(yàn)的相關(guān)資料,主要是防抖函數(shù)的應(yīng)用場景,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
vue在index.html中引入靜態(tài)文件不生效問題及解決方法
這篇文章主要介紹了vue在index.html中引入靜態(tài)文件不生效問題及解決方法,本文給大家分享兩種原因分析,通過實(shí)例代碼講解的非常詳細(xì) ,需要的朋友可以參考下2019-04-04
詳解vuex中mutations方法的使用與實(shí)現(xiàn)
這篇文章主要為大家詳細(xì)介紹了vuex中mutations方法的使用與實(shí)現(xiàn)的相關(guān)知識,文中的示例代碼簡潔易懂,具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以跟隨小編一起了解一下2023-11-11
通過vue-router懶加載解決首次加載時(shí)資源過多導(dǎo)致的速度緩慢問題
這篇文章主要介紹了vue-router懶加載解決首次加載時(shí)資源過多導(dǎo)致的速度緩慢問題,文中單獨(dú)給大家介紹了vue router路由懶加載問題,需要的朋友可以參考下2018-04-04
uni-app中App與webview雙向?qū)崟r(shí)通信詳細(xì)代碼示例
在移動應(yīng)用開發(fā)中,uni-app是一個(gè)非常流行的框架,它允許開發(fā)者使用一套代碼庫構(gòu)建多端應(yīng)用,包括H5、小程序、App等,這篇文章主要給大家介紹了關(guān)于uni-app中App與webview雙向?qū)崟r(shí)通信的相關(guān)資料,需要的朋友可以參考下2024-07-07
vue.js實(shí)現(xiàn)帶日期星期的數(shù)字時(shí)鐘功能示例
這篇文章主要介紹了vue.js實(shí)現(xiàn)帶日期星期的數(shù)字時(shí)鐘功能,涉及vue.js基于定時(shí)器的日期時(shí)間運(yùn)算與數(shù)值操作相關(guān)使用技巧,需要的朋友可以參考下2018-08-08
Vue3?在<script?setup>里設(shè)置組件name屬性的方法
這篇文章主要介紹了Vue3?在<script?setup>里設(shè)置組件name屬性的方法,本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2023-11-11

