第一次接觸神奇的前端框架vue.js
前言
入手2016最火前端框架之一vue.js。大概從網(wǎng)上找了些資料看了下vue.js,從網(wǎng)上的資料來看只能驚嘆其發(fā)展速度太快,讓我意外的是其作者是華人的前提下作品這么受歡迎。 網(wǎng)上的博客和教程各種組合。以至于我都有些感覺out。各種vue+webpack、vue+react、vue+es6+npm等等。琳瑯滿目。
開篇主要是初次了解下vue.js,包括v-model、v-if、v-else、v-show、v-for(2.0對(duì)$index和$key舍棄,2.0要用index屬性語(yǔ)法為 v-for="(person,index) in persons")、v-on。
看圖
看代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Vue.js CURD</title> <meta id="viewport" name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1"> <link rel="stylesheet" > <script src="https://unpkg.com/vue/dist/vue.js"></script> </head> <body> <div class="row" id="app"> <div class="col-xs-12 col-md-8"> <fieldset> <legend>New Person</legend> <div class="form-group"> <label>ID</label> <input type="text" v-model="newPerson.id"/> </div> <div class="form-group"> <label>Name:</label> <input type="text" v-model="newPerson.name"/> </div> <div class="form-group"> <label>Age:</label> <input type="text" v-model="newPerson.age"/> </div> <div class="form-group"> <label>Sex:</label> <select v-model="newPerson.sex"> <option value="Male">Male</option> <option value="Female">Female</option> </select> </div> <div class="form-group"> <label></label> <button @click="createorupdate">ok</button> </div> </fieldset> </div> <div class="col-xs-12 col-md-8"> <table class="table table-striped"> <thead> <tr> <th>Id</th> <th>name</th> <th>age</th> <th>sex</th> </tr> </thead> <tbody> <tr v-for="(person,index) in persons"> <td>{{person.id}}</td> <td>{{person.name}}</td> <td>{{person.age}}</td> <td>{{person.sex}}</td> <td><button @click="deletePerson(index)">delete</button></td> <td><button @click="update(index)">update</button></td> </tr> </tbody> </table> </div> </div> <script> Array.prototype.arrIndex=function(obj){ for(let i=0;i<this.length;i++){ var tmp=this[i]; if(tmp==obj){ return i; } } } var vm=new Vue({ el:'#app', data:{ editLock:1, newPerson:{ id:0, name:'', age:0, sex:'male' }, persons:[{ id:1, name: 'Jack', age: 30, sex: 'Male' }, { id:2, name: 'Bill', age: 26, sex: 'Male' }, { id:3, name: 'Tracy', age: 22, sex: 'Female' }, { id:4, name: 'Chris', age: 36, sex: 'Male' }] }, methods:{ create:function(){ this.persons.push(this.newPerson); this.newPerson={id:0,name:'',age:0,sex:'male'}; }, createorupdate:function(){ if(this.editLock===1){ this.persons.push(this.newPerson); }else{ //刪除老對(duì)象 var aindex=this.persons.arrIndex(this.newPerson); console.log(aindex); this.persons.splice(aindex,1); //插入新對(duì)象 this.persons.push(this.newPerson); } this.newPerson={id:0,name:'',age:0,sex:'male'}; }, deletePerson:function(idx){ this.persons.splice(idx,1); }, update:function(idx){ var p =this.persons[idx]; this.editLock=0; this.newPerson=p; } } }) </script> </body> </html>
參考資料:
https://cn.vuejs.org/v2/guide/routing.html
//chabaoo.cn/article/98791.htm
//chabaoo.cn/article/96426.htm
本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue,angular,avalon這三種MVVM框架優(yōu)缺點(diǎn)
- 前端框架Vue.js中Directive知識(shí)詳解
- 前端框架Vue.js構(gòu)建大型應(yīng)用淺析
- Vue2.0 UI框架ElementUI使用方法詳解
- vue.js中mint-ui框架的使用方法
- 前端框架學(xué)習(xí)總結(jié)之Angular、React與Vue的比較詳解
- Vue.js 2.0 和 React、Augular等其他前端框架大比拼
- 利用VUE框架,實(shí)現(xiàn)列表分頁(yè)功能示例代碼
- 基于Vuejs框架實(shí)現(xiàn)翻頁(yè)組件
- 前端主流框架vue學(xué)習(xí)筆記第二篇
相關(guān)文章
基于element-ui表格的二次封裝實(shí)現(xiàn)
本文主要介紹了基于element-ui表格的二次封裝實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07vue 組件使用中的一些細(xì)節(jié)點(diǎn)
這篇文章主要介紹了vue 組件使用中的一些細(xì)節(jié)點(diǎn),大概有兩大細(xì)節(jié)點(diǎn),本文通過基礎(chǔ)實(shí)例給大家介紹的非常詳細(xì),需要的朋友參考下吧2018-04-04Ant?Design-vue?解決input前后空格問題(推薦)
最近做項(xiàng)目遇到這樣一個(gè)問題輸入框不允許有前后空格但字符中間可以有空格,怎么解決這個(gè)問題呢,接下來小編把a(bǔ)nt?Design-vue?解決input前后空格問題的實(shí)現(xiàn)代碼分享給大家,感興趣的朋友一起看看吧2022-10-10vue跳轉(zhuǎn)頁(yè)簽傳參并查詢參數(shù)的保姆級(jí)教程
這篇文章主要介紹了vue跳轉(zhuǎn)頁(yè)簽傳參并查詢參數(shù)的保姆級(jí)教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04Vue中實(shí)現(xiàn)路由跳轉(zhuǎn)傳參的4種方式
本文詳盡的講了在Vue項(xiàng)目中,如何實(shí)現(xiàn)路由跳轉(zhuǎn)傳參的4四種方式(2大路由跳轉(zhuǎn)方式,每種方式包括4種路由傳參實(shí)現(xiàn)形式),以及每種方式中實(shí)現(xiàn)路由跳轉(zhuǎn)包括路由傳參的方法的各種寫法,需要的朋友可以參考下2024-04-04vue使用canvas實(shí)現(xiàn)移動(dòng)端手寫簽名
這篇文章主要為大家詳細(xì)介紹了基于vue使用canvas實(shí)現(xiàn)移動(dòng)端手寫簽名,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09Vue數(shù)據(jù)更新但頁(yè)面沒有更新的多種情況問題及解決
這篇文章主要介紹了Vue數(shù)據(jù)更新但頁(yè)面沒有更新的多種情況問題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07基于Vue3和element-plus實(shí)現(xiàn)登錄功能(最終完整版)
這篇文章主要介紹了基于Vue3和element-plus實(shí)現(xiàn)一個(gè)完整的登錄功能,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03使用keep-alive時(shí),數(shù)據(jù)無法刷新的問題及解決
這篇文章主要介紹了使用keep-alive時(shí),數(shù)據(jù)無法刷新的問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07