魔法のフロントエンド フレームワーク vue.js とのファーストコンタクト

高洛峰
リリース: 2016-12-03 10:11:36
オリジナル
1688 人が閲覧しました

はじめに

2016 年に最も人気のあるフロントエンド フレームワークの 1 つである vue.js から始めましょう。おそらくインターネットで何かの情報を見つけて vue.js を見たのですが、インターネットの情報から判断すると、この作品が中国人であることを考えると、その急速な発展には驚かされるばかりです。 オンラインのブログとチュートリアルのさまざまな組み合わせ。あまりにも多すぎて、少し気分が悪くなった。さまざまな vue+webpack、vue+react、vue+es6+npm など。目まぐるしいアイテムの数々。 3日間勉強しなかったら、劉少奇に追いつくのは本当に不可能です。

始まりは主に、v-model、v-if、v-else、v-show、v-for ($index と $key は 2.0 で破棄され、 2.0 のインデックス属性の構文は、v -for="(person,index) in people")、v-on です。

写真を見てください

魔法のフロントエンド フレームワーク vue.js とのファーストコンタクト

コードを見てください

<!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" href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css">
 <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:&#39;#app&#39;,
 data:{
 editLock:1,
 newPerson:{
 id:0,
 name:&#39;&#39;,
 age:0,
 sex:&#39;male&#39;
 },
 persons:[{
 id:1,
 name: &#39;Jack&#39;,
 age: 30,
 sex: &#39;Male&#39;
 }, {
 id:2,
 name: &#39;Bill&#39;,
 age: 26,
 sex: &#39;Male&#39;
 }, {
 id:3,
 name: &#39;Tracy&#39;,
 age: 22,
 sex: &#39;Female&#39;
 }, {
 id:4,
 name: &#39;Chris&#39;,
 age: 36,
 sex: &#39;Male&#39;
 }]
 },
 methods:{
 create:function(){
 this.persons.push(this.newPerson);
 this.newPerson={id:0,name:&#39;&#39;,age:0,sex:&#39;male&#39;};
 },
 createorupdate:function(){
 if(this.editLock===1){
 this.persons.push(this.newPerson);
 }else{
 //删除老对象
 var aindex=this.persons.arrIndex(this.newPerson);
 console.log(aindex);
 this.persons.splice(aindex,1);
 //插入新对象
 this.persons.push(this.newPerson);
 }
 
 this.newPerson={id:0,name:&#39;&#39;,age:0,sex:&#39;male&#39;};
 },
 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>
ログイン後にコピー


関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!