≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > vue.js

基于Vue实现图书管理功能

人气:275 时间:2019-04-07

这篇文章主要为大家详细介绍了基于Vue实现图书管理功能,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!

本文实例为大家分享了vue简单的图书管理具体代码,供大家参考,具体内容如下

代码如下:


<table class="table table-bg table-border table-bordered">
 <tr>
  <th>ID</th>
  <th>书名</th>
  <th>作者</th>
  <th>价格</th>
  <th>操作</th>
 </tr>
 <tr v-for="(book,index) in books">
  <td>{{book.id}}</td>
  <td>{{book.name}}</td>
  <td>{{book.author}}</td>
  <td>{{book.price}}</td>
  <td>
   <button class="btn" @click="delBook(index)">删除</button>
  </td>
 </tr>
</table>

<fieldset>
 <legend>添加新书</legend>
 <p>书名:<input type="text" v-model="newBook.name"></p>
 <p>作者:<input type="text" v-model="newBook.author"></p>
 <p>价格:<input type="text" v-model="newBook.price"></p>
 <p><button class="btn" @click="addBook">添加</button></p>
</fieldset>

<script>
new Vue({
 el:'#books',
 data:{
  books:[
   {id:1, name:'红楼梦', author:'曹雪芹', price:'1'},
   {id:2, name:'西游记', author:'吴承恩', price:'2'},
   {id:3, name:'水浒传', author:'施耐庵', price:'3'}
  ],
  newBook:{
   id:0,
   name:'',
   author:'',
   price:''
  }
 },
 methods:{
  delBook:function(idx){
   if(window.confirm('确认要删除?')){
    this.books.splice(idx, 1);
   }

  },
  addBook:function(){
   // 约束
   if(this.newBook.name.length == 0) {
    alert('书名不能为空');
    return;
   } 

   if(this.newBook.author.length == 0){
    alert('书的作者不能为空');
    return;
   }

   if(this.newBook.price.length == 0){
    this.newBook.price = '0'
   } 

   // 计算插入id
   var maxId = 0;
   for(var i=0; i<this.books.length; i++){
    if(maxId<this.books[i].id){
     maxId = this.books[i].id;
    }
   }
   this.newBook.id = maxId+1;

   // 插入到 books中
   this.books.push(this.newBook);

   // 清空新书
   this.newBook = {};
  }
 }
});
</script>

效果图:

【q1010.com温馨提示:图片暂缺】

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持四海网。

本文来自:http://www.q1010.com/184/3678-0.html

注:关于基于Vue实现图书管理功能的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:vue.js

您可能感兴趣的文章

  • vue中axios处理http发送请求的示例(Post和get)
  • vue router自动判断左右翻页转场动画效果
  • vue2.x select2 指令封装分析
  • vue router demo分析
  • Vue实现数字输入框中分割手机号码的示例
  • Vue-router结合transition实现app前进后退动画切换效果的实例
  • vue mintui-Loadmore结合实现下拉刷新和上拉加载示例
  • vue跨域解决方法
  • Vue中封装input组件的实例分析
  • vue与TypeScript集成配置最简教程(推荐)
上一篇:浅谈vue路径优化之resolve
下一篇:vue router demo分析
热门文章
  • Vue 报错TypeError: this.$set is not a function 的解决方法
  • vue实现动态添加数据滚动条自动滚动到底部的示例代码
  • vue项目设置scrollTop不起作用(总结)
  • vue项目中使用vue-i18n报错的解决方法
  • iview实现select tree树形下拉框的示例代码
  • 分析关于element级联选择器数据回显问题
  • vue项目打包后打开页面空白解决办法
  • 解决element ui select下拉框不回显数据问题的解决
  • element-ui table span-method(行合并)的实现代码
  • element-ui 设置菜单栏展开的方法
  • 最新文章
    • 理解vue ssr原理并自己搭建简单的ssr框架
    • vue favicon设置以及动态修改favicon的方法
    • vue-router启用history模式下的开发及非根目录部署方法
    • 从零开始在NPM上发布一个Vue组件的方法步骤
    • Element input树型下拉框的实现代码
    • Vue 报错TypeError: this.$set is not a function 的解决方法
    • Vue.js组件高级特性实例分析
    • 浅谈VueJS SSR 后端绘制内存泄漏的相关解决经验
    • 分析Vue.js自定义tipOnce指令用法实例
    • 浅谈vuex actions和mutation的异曲同工

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。