前言
入手2016最火前端框架之一vue.js。大概从网上找了些资料看了下vue.js,从网上的资料来看只能惊叹其发展速度太快,让我意外的是其作者是华人的前提下作品这么受欢迎。 网上的博客和教程各种组合。以至于我都有些感觉out。各种vue+webpack、vue+react、vue+es6+npm等等。琳琅满目。真是三天不学习赶不上刘少奇。
开篇主要是初次了解下vue.js,包括v-model、v-if、v-else、v-show、v-for(2.0对$index和$key舍弃,2.0要用index属性语法为 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" 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:'#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{ //删除老对象 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:'',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>

VueUse 是 Anthony Fu 的一个开源项目,它为 Vue 开发人员提供了大量适用于 Vue 2 和 Vue 3 的基本 Composition API 实用程序函数。本篇文章就来给大家分享几个我常用的几个 VueUse 最佳组合,希望对大家有所帮助!

Vue3如何更好地使用qrcodejs生成二维码并添加文字描述?下面本篇文章给大家介绍一下Vue3+qrcodejs生成二维码并添加文字描述,希望对大家有所帮助。

如何使用VueRouter4.x?下面本篇文章就来给大家分享快速上手教程,介绍一下10分钟快速上手VueRouter4.x的方法,希望对大家有所帮助!

本篇文章带大家聊聊vue指令中的修饰符,对比一下vue中的指令修饰符和dom事件中的event对象,介绍一下常用的事件修饰符,希望对大家有所帮助!

本篇文章给大家整理分享8个GitHub上很棒的的 Vue 项目,都是非常棒的项目,希望当中有您想要收藏的那一个。

如何覆盖组件库样式?下面本篇文章给大家介绍一下React和Vue项目中优雅地覆盖组件库样式的方法,希望对大家有所帮助!


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

WebStorm Mac版
好用的JavaScript开发工具

Dreamweaver Mac版
视觉化网页开发工具

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

记事本++7.3.1
好用且免费的代码编辑器