亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

vue實現圖書管理系統

瀏覽:52日期:2022-10-14 18:07:02

本文實例為大家分享了vue實現圖書管理系統的具體代碼,供大家參考,具體內容如下

組件代碼

<template> <div id='app'> <div class='grid'> <div> <h1>圖書管理</h1> <div class='book'> <div> <label for='id' v-focus> 編號: </label> <input type='text' v-model='id' :disabled='flag'> <label for='name'> 名稱: </label> <input type='text' v-model='name'> <button @click='add(addOrUpdate)' :disabled='subFlag'>提交</button> </div> </div> </div> <div class='total'> <span>圖書總數:</span> <span>{{ totalNum }}</span> </div> <table> <thead> <tr> <th>編號</th> <th>名稱</th> <th>時間</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for='book in books'> <td> {{ book.id }} </td> <td> {{ book.name }} </td> <td> {{ book.date | date-format }} </td> <td> <a href='http://www.aoyou183.cn/bcjs/10460.html' @click.prevent=' rel='external nofollow' updateBook(book.id)'>修改</a> <span>|</span> <a href='http://www.aoyou183.cn/bcjs/10460.html' @click.prevent = ’deleteBook(book.id)’>刪除</a> </td> </tr> </tbody> </table> </div> </div></template><script> export default { data(){ return{ books:[ { id: 1, name: ’三國演義’, date: 2525609975000 }, { id: 2, name: ’水滸傳’, date: 2525609975000 }, { id: 3, name: ’紅樓夢’, date: 2525609975000 }, { id: 4, name: ’西游記’, date: 2525609975000 } ], id:’’, name:’’, flag:false, // id輸入框是否可修改標識 addOrUpdate: 0, // 0代表添加 1代表修改 subFlag:false, // 提交按鈕是否禁用(圖書存在時禁用) } }, methods:{ // 添加圖書的方法 add() { if(this.addOrUpdate===0){ // 添加圖書 this.books.push({ id: this.id, name: this.name, date: new Date() }); }else{ const book = this.books.filter((book)=>{ return book.id === this.id; }); book[0].name = this.name } // 添加之后清空input框 this.id = ’’; this.name = ’’; this.flag = false }, // 更新圖書的方法 updateBook(id){this.addOrUpdate = 1; // 需要修改的當前圖書信息 const book = this.books.filter((book)=>{ return book.id === id; }); // 讓input框顯示相應內容 this.id = book[0].id; this.name = book[0].name; this.flag = true; }, deleteBook(id){ // 獲取當前圖書的索引 const index = this.books.findIndex((book)=>{ return book.id === id }); this.books.splice(index, 1) } }, computed:{ totalNum(){return this.books.length } }, // 自定義局部指令 directives:{ focus:{ inserted(el){ // 自動聚焦 el.focus() } } }, // 監視圖書是否存在 watch:{ name:{ deep:true, handler(val){ const book = this.books.find((book)=>{ return book.name === val }); if(book){ this.subFlag = true }else{ this.subFlag = false } } } } }</script><style type='text/css'> .grid { margin: auto; width: 530px; text-align: center; } .grid table { border-top: 1px solid #C2D89A; width: 100%; border-collapse: collapse; } .grid th,td { padding: 10px; border: 1px dashed #F3DCAB; height: 35px; line-height: 35px; } .grid th { background-color: #F3DCAB; } .grid .book { padding-bottom: 10px; padding-top: 5px; background-color: #F3DCAB; } .grid .total { height: 30px; line-height: 30px; background-color: #F3DCAB; border-top: 1px solid #C2D89A; }</style>

過濾器文件index.js

vue實現圖書管理系統

import Vue from ’vue’import format from ’date-fns/format’// 自定義過濾器Vue.filter(’date-format’, function (value, formatStr=’yyyy-MM-dd HH:mm:ss’) { return format(value, formatStr)});

main.js引入

import ’./filters’

vue實現圖書管理系統

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 伊人婷婷色香五月综合缴缴情 | 欧美国产综合在线 | 午夜精品久视频在线观看 | 57pao国产成永久免费视频 | 美女的下部隐私网站99 | 91精品啪在线观看国产日本 | 免费一级毛片麻豆精品 | 国产黄大片在线视频 | 精品一区精品二区 | 毛片随便看 | 精品色综合 | 黄www片| 中国人免费的片 | 亚洲午夜久久久久影院 | 91精品啪在线看国产网站 | 野外啪啪抽搐一进一出 | 日本特黄绿像大片免费看 | 免费摸碰碰视频在线观看 | 在线一区二区观看 | 亚洲国产二区三区 | 国产最新精品2020好看的 | 青青国产成人久久91网 | 久久有精品 | 国产综合影院 | 特级做a爰片毛片免费看一区 | 日韩欧美国产精品 | 成人一区二区丝袜美腿 | 国产精品果冻 | 欧美日韩在线播放一区二区三区 | 久久机热这里只有精品无需 | 97视频免费观看2区 97午夜 | 欧美日韩一区在线观看 | a级特黄毛片| 国产一级精品高清一级毛片 | 一级毛片美国一级j毛片不卡 | 高清性色生活片久久久 | www.色婷婷| 欧美激情一区二区三区不卡 | 亚洲综合精品香蕉久久网97 | 国产精品久久免费 | 国产刚刚发育被强j在线播放 |