年后公司的项目要求用到vue.js知识,我angular没有学,node.js和react也只是了解了一点点,所以学起来比较困难。如果你想学vue.js的知识,推荐网址:http://vuejs.org/
详细内容如下:
一、图书管理demo用的知识点
1、bootstrap:http://getbootstrap.com/
2、vuejs:http://getbootstrap.com/
具体代码如下:
html部分
<div id="app" class="container"> <table class="table table-bordered"> <div v-for = "book in books"> <tr> <th>书名</th> <th>书的价格</th> <th>书的数量</th> <th>小计</th> <th>操作</th> </tr> <tr v-for = "(index,book ) in books"> <td>{{book.name}}</td> <td>{{book.price}}</td> <td><button @click="book.count&&book.count--">-</button><input type="text" v-model="book.count" /><button @click="book.count++">+</button></td> <td>{{book.price*book.count}}</td> <td><button class="btn btn-danger" @click="deleteBook(book)">删除</button></td> </tr> <tr> <td colspan="5"> 总价{{total}} </td> </tr> </div> </table> <div class="form-group"> <label for="bookname" id="bookname">书名</label> <input type="text" v-model="list.name" class="form-control"/> </div> <div class="form-group"> <label for="bookprice" id="bookprice">价格</label> <input type="text" v-model="list.price" class="form-control"/> </div> <div class="form-group"> <label for="bookcount" id="bookcount">数量</label> <input type="text" v-model="list.count" class="form-control"/> </div> <div class="form-group"> <button class="btn btn-primary" @click="add">添加</button> </div> </div>
脚本部分
<script src="js/vue.js"></script> <script> var vm = new Vue({ el:"#app", data:{ books:[ {name:'VUE js',price:40,count:1}, {name:'NODE js',price:20,count:1}, {name:'REACT js',price:30,count:1}, {name:'ANGULAR js',price:100,count:1}, {name:'JQUERY js',price:50,count:1}, ], list:{ name:'', price:'', count:'' } }, methods:{ deleteBook(book){ // vue 给我们提供了一个 $remove的方法,在数组中删除 this.books.$remove(book); /*this.books = this.books.filter((item)=>{ return item != book })*/ }, add(){ this.books.push(this.list); this.list = { name:'', price:'', count:'' } } }, computed:{ total(){ var sum = 0; this.books.forEach(item =>{ sum += item.price*item.count; }) return sum; } } }); </script>
遇到难点总结