vue案例之圖書管理(簡(jiǎn)易計(jì)算器)

<!DOCTYPE?html>

<html?lang="en">

<head>

????<meta?charset="UTF-8">

????<meta?name="viewport"?content="width=device-width,?initial-scale=1.0">

????<title>vue基礎(chǔ)之計(jì)算器</title>

????<script?src="js/vue.min.js"></script>

</head>

<body>

????<!--?案例一計(jì)算器部分?-->

????<!--?<div?class="jisuanqi">

????????<h1>簡(jiǎn)答計(jì)算器</h1>

????????<div>

????????????<span?>數(shù)值A(chǔ):</span>

????????????<input?type="text"?v-model='a'>

????????</div>

????????<div>

????????????<span?>數(shù)值B:</span>

????????????<input?type="text"?v-model='b'>

????????</div>

????????<div?class="fangshi">

????????????<span>請(qǐng)選擇運(yùn)算方式</span>

????????????<button?@click="panduan">+</button>

????????????<button?@click="panduan">-</button>

????????????<button?@click?=?'panduan'>*</button>

????????????<button?@click?=?'panduan'>/</button>

????????</div>

????????<button?v-on:click="jisuan">計(jì)算</button>

????????<div>計(jì)算結(jié)果

????????????<span?v-html="result"></span>

????????</div>

????</div>?-->

????<!--?計(jì)算器js部分?-->

????<!--?<script>


????????var?vue?=?new?Vue({

????????????el:".jisuanqi",

????????????data:{

????????????????a:'',

????????????????b:'',

????????????????result:'',

????????????????yunsuan:''

????????????},

????????????methods:{

????????????????jisuan:function(){

????????????????????if(this.yunsuan?==?'+'){

????????????????????????this.result?=?parseFloat(this.a)?+?parseFloat(this.b)

????????????????????}else?if?(this.yunsuan?==?'-'){

????????????????????????this.result?=?parseFloat(this.a)?-?parseFloat(this.b)

????????????????????}else?if?(this.yunsuan?==?'*'){

????????????????????????this.result?=?parseFloat(this.a)?*?parseFloat(this.b)

????????????????????}else?if?(this.yunsuan?==?'/'){

????????????????????????this.result?=?parseFloat(this.a)?/?parseFloat(this.b)

????????????????????}


????????????????},

???????????????panduan(v){

????????????????this.yunsuan?=?v.target.innerHTML

???????????????}

????????????}


????????})

????</script>?-->

????<!--?案例二?選項(xiàng)卡功能?-->

????<!--?<style>

????????*?{

????????????padding:?0;

????????????margin:?0;

????????}

????????.clear:after,

????????.clear:before{

????????????content:?"";

????????????display:?block;

????????????height:?0;

????????????clear:both

????????}

????????.clear?{

????????????*zoom:1

????????}


????????li?{

????????????list-style:?none;

????????????float:?left;

????????????text-align:?center;

????????????padding:?40px?100px;

????????????border:?1px?solid?pink;

????????}

????????img?{

????????????width:?702px;

????????????height:?400px;


????????}

????????.bottom?div?{

????????????display:?none;

????????}

????????.bottom?.current_img{

????????????display:?block;

????????}

????????.current?{

????????????background-color:?orange;

????????}

????</style>

????<div?class="xuanxiangka">

????????<div?class="top">

????????????<ul?class="clear">

????????????????<li?@click='change(index)'?:key="item.id"?:class="current_index==index?'current':''"?v-for="(item,index)?in?shuju">{{item.title}}</li>

????????????</ul>

????????</div>

????????<div?class="bottom">

????????????<div?:key="item.id"?v-for="(item,index)?in?shuju"?:class="current_index==index?'current_img':''">

????????????????<img?:src="item.img"?alt="">

????????????</div>

????????</div>

????</div>?-->

????<!--?js部分?-->

????<!--?<script>

????var?vue?=?new?Vue({

????????el:'.xuanxiangka',


????????data:{

????????????//要拿到當(dāng)前點(diǎn)擊選項(xiàng)卡的索引號(hào)進(jìn)行判斷

????????????current_index:0,

????????????shuju:[{

????????????????????id:0,

????????????????????title:"蘋果",

????????????????????img:"img/apple.jpg"

????????????????},{

????????????????????id:1,

????????????????????title:"橘子",

????????????????????img:"img/orange.jpg"

????????????????},{

????????????????????id:2,

????????????????????title:"香蕉",

????????????????????img:"img/banner.jpg"

????????????????}]

????????},

????????methods:{

????????????change:function(index){

????????????????//通過改變current_index變量來控制類名的變化?記住訪問data里數(shù)據(jù)或者變量的時(shí)候一定要使用this

????????????????this.current_index?=?index

????????????}

????????}

????})

</script>?-->

????<!--?案例三?圖書管理案例功能?-->

????<!--?圖書樣式部分?-->

????<style>

????????h1?{

????????????text-align:?center;

????????}


????????.tushu?{

????????????width:?500px;

????????????margin:?0?auto;

????????}


????????table?{

????????????width:?500px;

????????}


????????th,

????????tr,

????????td?{

????????????height:?40px;

????????????line-height:?40px;

????????????text-align:?center;

????????????border:?1px?solid?#999;

????????????border-right:?none;

????????????border-top:?none;

????????}


????????.top?{

????????????background-color:?#ccc;

????????????line-height:?40px;

????????????text-align:?center;

????????}

????</style>

????<div?class="tushu">

????????<h1>圖書管理</h1>

????????<div?class="top">

????????????<span>編號(hào)</span>

????????????<input?type="text"?v-model='one'?:disabled='dis'>

????????????<span>名稱</span>

????????????<input?type="text"?v-model='two'>

????????????<button?@click='tijiao'>提交</button>

????????</div>

????????<div?class="center">

????????????<table>

????????????????<tr?class="top">

????????????????????<th>編號(hào)</th>

????????????????????<th>名稱</th>

????????????????????<th>時(shí)間</th>

????????????????????<th>操作</th>

????????????????</tr>

????????????????<tr?:key='item.id'?v-for="item?in?shuju">

????????????????????<td>{{item.id}}</td>

????????????????????<td>{{item.name}}</td>

????????????????????<td>{{item.date?|?guolv('yyyy-MM-dd?HH-mm-ss')}}</td>

????????????????????<td>

????????????????????????<!--?@click.prevent點(diǎn)擊阻止默認(rèn)行為?-->

????????????????????????<a?href=""?@click.prevent='xiugai(item.id)'>修改</a>

????????????????????????<span>|</span>

????????????????????????<a?href=""?@click.prevent='del(item.id)'>刪除</a>

????????????????????</td>

????????????????</tr>

????????????</table>

????????</div>

????</div>

????<!--?js部分?-->

????<script>

????????var?newdater?=?new?Date();

????????Vue.filter('guolv',?function(val,?canshu)?{

????????????if?(canshu?==?'yyyy-MM-dd?HH-mm-ss')?{

????????????????var?o?=?{

????????????????????y:?val.getFullYear(),

????????????????????m:?val.getMonth()?+?1,

????????????????????d:?val.getDate(),

????????????????????h:?val.getHours(),

????????????????????mi:?val.getMinutes(),

????????????????????s:?val.getSeconds()

????????????????}

????????????????return?o.y?+?'-'?+?o.m?+?'-'?+?o.d?+?"????"?+?o.h?+?'時(shí)'?+?o.mi?+?'分'?+?o.s?+?'秒'

????????????}

????????})

????????var?vue?=?new?Vue({

????????????el:?'.tushu',

????????????data:?{

????????????????one:?'',

????????????????two:?'',

????????????????dis:?false,

????????????????zhta:?true,

????????????????shuju:?[{

????????????????????id:?1,

????????????????????name:?'西游記',

????????????????????date:?newdater

????????????????},?{

????????????????????id:?2,

????????????????????name:?'紅樓夢(mèng)',

????????????????????date:?newdater

????????????????},?{

????????????????????id:?3,

????????????????????name:?'三國(guó)演義',

????????????????????date:?newdater

????????????????},?{

????????????????????id:?4,

????????????????????name:?'水滸傳',

????????????????????date:?newdater

????????????????}]

????????????},

????????????methods:?{

????????????????//當(dāng)點(diǎn)擊提交的時(shí)候?通過編號(hào)是否能修改信息判斷是新增還是修改

????????????????tijiao:?function()?{

????????????????????//修改提交?循環(huán)數(shù)組?拿到id號(hào)?跟編號(hào)做對(duì)比

????????????????????if?(this.dis)?{

????????????????????????this.shuju.forEach(element?=>?{

????????????????????????????if?(element.id?==?this.one)?{

????????????????????????????????element.name?=?this.two

????????????????????????????????return?true

????????????????????????????}

????????????????????????});

????????????????????}?else?{

????????????????????????//新增數(shù)據(jù)追加數(shù)組

????????????????????????var?arr?=?[]

????????????????????????arr.id?=?this.one

????????????????????????arr.name?=?this.two

????????????????????????arr.date?=?newdater

????????????????????????this.idrepeat(arr.id,?this.shuju)

????????????????????????console.log(this.zhta)

????????????????????????if?(this.zhta?==?true)?{

????????????????????????????this.shuju.push(arr)

????????????????????????}

????????????????????}

????????????????????this.one?=?''

????????????????????this.two?=?''

????????????????????this.dis?=?false

????????????????????this.zhta?=?true

????????????????},

????????????????xiugai:?function(id)?{

????????????????????//?當(dāng)點(diǎn)擊修改的時(shí)候遍歷數(shù)組?把內(nèi)容展示在輸入框中

????????????????????for?(item?in?this.shuju)?{

????????????????????????//?代表的是當(dāng)前點(diǎn)擊的id?形參的id代表的是點(diǎn)擊當(dāng)前的編號(hào)

????????????????????????//?console.log(this.shuju[item].id);

????????????????????????if?(this.shuju[item].id?==?id)?{

????????????????????????????this.one?=?this.shuju[item].id

????????????????????????????this.two?=?this.shuju[item].name

????????????????????????}

????????????????????????//?編號(hào)置灰不可更改

????????????????????????this.dis?=?true

????????????????????}

????????????????},

????????????????del:?function(id)?{

????????????????????//?當(dāng)點(diǎn)擊刪除的時(shí)候查找一下當(dāng)前id?然后使用splice刪掉

????????????????????//?console.log(id);

????????????????????var?index?=?this.shuju.findIndex(function(item)?{

????????????????????????if?(item.id?==?id)?{

????????????????????????????return?item

????????????????????????}

????????????????????})

????????????????????this.shuju.splice(index,?1)

????????????????},

????????????????//點(diǎn)擊提交的時(shí)候需要判斷是不是有id重復(fù)的

????????????????idrepeat(xin,?jiu)?{

????????????????????let?_this?=?this

????????????????????jiu.forEach(function(item,?index)?{

????????????????????????if?(item.id?==?xin)?{

????????????????????????????alert('有相同的id信息焙蚓,請(qǐng)重新輸入')

????????????????????????????_this.zhta?=?false

????????????????????????}

????????????????????????console.log(_this.zhta)

????????????????????})

????????????????}

????????????}

????????})

????</script>

</body>

</html>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市箫荡,隨后出現(xiàn)的幾起案子择同,更是在濱河造成了極大的恐慌速客,老刑警劉巖喇颁,帶你破解...
    沈念sama閱讀 217,657評(píng)論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件侈玄,死亡現(xiàn)場(chǎng)離奇詭異古掏,居然都是意外死亡宜肉,警方通過查閱死者的電腦和手機(jī)匀钧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來谬返,“玉大人之斯,你說我怎么就攤上這事∏猜粒” “怎么了佑刷?”我有些...
    開封第一講書人閱讀 164,057評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)酿炸。 經(jīng)常有香客問我瘫絮,道長(zhǎng),這世上最難降的妖魔是什么填硕? 我笑而不...
    開封第一講書人閱讀 58,509評(píng)論 1 293
  • 正文 為了忘掉前任麦萤,我火速辦了婚禮,結(jié)果婚禮上扁眯,老公的妹妹穿的比我還像新娘壮莹。我一直安慰自己,他們只是感情好姻檀,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,562評(píng)論 6 392
  • 文/花漫 我一把揭開白布命满。 她就那樣靜靜地躺著,像睡著了一般绣版。 火紅的嫁衣襯著肌膚如雪胶台。 梳的紋絲不亂的頭發(fā)上歼疮,一...
    開封第一講書人閱讀 51,443評(píng)論 1 302
  • 那天,我揣著相機(jī)與錄音概作,去河邊找鬼腋妙。 笑死,一個(gè)胖子當(dāng)著我的面吹牛讯榕,可吹牛的內(nèi)容都是我干的骤素。 我是一名探鬼主播,決...
    沈念sama閱讀 40,251評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼愚屁,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼济竹!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起霎槐,我...
    開封第一講書人閱讀 39,129評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤送浊,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后丘跌,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體袭景,經(jīng)...
    沈念sama閱讀 45,561評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,779評(píng)論 3 335
  • 正文 我和宋清朗相戀三年闭树,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了耸棒。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,902評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡报辱,死狀恐怖与殃,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情碍现,我是刑警寧澤幅疼,帶...
    沈念sama閱讀 35,621評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站昼接,受9級(jí)特大地震影響爽篷,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜辩棒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,220評(píng)論 3 328
  • 文/蒙蒙 一狼忱、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧一睁,春花似錦钻弄、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春瘤泪,著一層夾襖步出監(jiān)牢的瞬間灶泵,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工对途, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留赦邻,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,025評(píng)論 2 370
  • 正文 我出身青樓实檀,卻偏偏與公主長(zhǎng)得像惶洲,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子膳犹,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,843評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • <!DOCTYPEhtml> vue之組件開發(fā)案例 *{ padding:0; margin:0; } a{ t...
    丑吖吖閱讀 655評(píng)論 0 0
  • 方便起見不分parameter[形參恬吕,出現(xiàn)在函數(shù)定義中]和argument[實(shí)參,其值為傳入函數(shù)的值]须床,一律當(dāng)作a...
    東月三二閱讀 385評(píng)論 0 0
  • # vue 面試題 性能優(yōu)化: 1.passive 是性能優(yōu)化的一種方案铐料,如果有 passive 那么意味著 ev...
    徒步旅行_72c5閱讀 440評(píng)論 0 1
  • Vue 實(shí)例 屬性和方法 每個(gè) Vue 實(shí)例都會(huì)代理其 data 對(duì)象里所有的屬性:var data = { a:...
    云之外閱讀 2,209評(píng)論 0 6
  • 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭豺旬,有人歡樂有人憂愁钠惩,有人驚喜有人失落,有的覺得收獲滿滿有...
    陌忘宇閱讀 8,536評(píng)論 28 53