热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

利用vue.js把静态json绑定bootstrap的table

直接上代码嘻嘻,发现bootstrap+vue.js拿来做原型效率挺高,以后就这样做原型<!DOCTYPEhtml><html><head>

直接上代码

嘻嘻,发现bootstrap+vue.js拿来做原型效率挺高,以后就这样做原型


<html>
<head>
<meta charset="UTF-8">
<title>Documenttitle>

<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.js">script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js">script>
<script src="https://unpkg.com/vue/dist/vue.js">script>
head>
head>
<body>
<div class="container">


<div class="col-md-6 col-md-offset-3">
<h1>Vue demoh1>
<div id="app">
<table class="table">
<tr>
<td><input type="checkbox">td>
<td>idtd>
<td>书名td>
<td>作者td>
<td>价格td>
tr>
<tr v-for="book in books ">
<td>
<label>
<input type="checkbox" v-bind:value="book.id" v-model="checkedNames">
label>
td>
<td>{{book.id}}td>
<td>{{book.name}}td>
<td>{{book.author}}td>
<td>{{book.price}}td>
tr>
<tr>
<td colspan="5">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">addbutton>
<button type="button" class="btn btn-primary" v-on:click="delItems">deletebutton>
td>
tr>
table>
<p>Checked names: {{ checkedNames }}p>



<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×span><span class="sr-only">Closespan>button>
<h4 class="modal-title" id="myModalLabel">Modal titleh4>
div>
<div class="modal-body">
<input class="form-control" placeholder="input id" v-model="book.id">
<input class="form-control" placeholder="input author" v-model="book.author">
<input class="form-control" placeholder="input name" v-model="book.name">
<input class="form-control" placeholder="input price" v-model="book.price">
div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Closebutton>
<button type="button" class="btn btn-primary" data-dismiss="modal" v-on:click="addItem">Save changesbutton>
div>
div>
div>
div>


div>
div>


div>
body>
<script>
new Vue({
el: '#app',
data: {
book: {
id: '0',
author: '',
name: '',
price: ''
},
checkedNames: [],
books: [{
id: '1',
author: '曹雪芹',
name: '红楼梦',
price: 32.0
}, {
id: '2',
author: '施耐庵',
name: '水浒传',
price: 30.0
}, {
id: '3',
author: '罗贯中',
name: '三国演义',
price: 24.0
}, {
id: '4',
author: '吴承恩',
name: '西游记',
price: 20.0
}]
},
methods:{
delItems : function() {
for (var i = 0 ; i <this.checkedNames.length ; i++) {
for(var j = 0 ; j <this.books.length ; j++){
var cur_book = this.books[j];
if(cur_book.id == this.checkedNames[i]){
this.books.splice(j,1);
}
}
}
this.checkedNames = [];
},
addItem : function(){
this.books.push(this.book);
}
}
})
script>
html>

推荐阅读
author-avatar
手浪用户2502941303
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有