Using vue and bootstrap to write simple user information


1.v-model = "" for bi-directional data binding of input form logical layer and rendering layer

2.v-on:click='add() 'click method binding

3.v-for='(item,index) in myData' pass history group {{index}} {{} {{item.age}}} is applicable to vue version 2.0

4.v-for='(item,index,key) in myData' traverses json {{index}} {{item}} {{key}} for vue version 2.0

5.v-on:click="currentUser=index" directly bind the data of click event change logic layer. currentUser here is the data of logic layer

6.v-show="myData.length!=0" v-show can directly use the data of logic layer to judge whether it is displayed or hidden according to the following Boolean values

7. < div class = "modal" role ='dialog 'id = "layer" > modal dialog is the mask ID used to contact trigger elements

8. Data toggle = 'modal' alternately displays the hidden mask frame. Data target = '(layer' determines the target modal box

9. Data dismission ='modal 'click to disappear the target element

Design sketch:

<!DOCTYPE html>
<html lang="en">
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0" >
	<!-- Latest version of Bootstrap core CSS file -->
<link rel="stylesheet" href="">
	<script src='../jquery-3.2.1.min.js'></script>
	<script src='bootstrap.js'></script>
	<script src='vue.js'></script>
		table td {vertical-align: middle !important;}
<div class="container">

	<form action="" role='form' class="">
		<div class="form-group">
			<label for="username" class="">User name:</label>
			<input type="text" id="username" class="form-control" v-model="username" placeholder="enter one user name">
		<div class="form-group">
			<label for="age">Age:</label>
			<input type="text" id="age" class="form-control" v-model="age" placeholder="Please enter age">
		<div class="form-group">
			<input type="button" value="Add to" class="btn btn-primary" v-on:click='add()'>
			<input type="reset" value="Reset" class="btn btn-warning">
	<table class="table table-bordered table-hover">
	<caption class="h4 text-info text-center">User information table</caption>
		<tr class="text-danger">
			<th class="text-center">Serial number</th>
			<th class="text-center">Full name</th>
			<th class="text-center">Age</th>
			<th class="text-center">operation</th>
		<tr class="text-center" v-for='(item,index) in myData'>
				<button class="btn btn-danger btn-xs" data-toggle='modal' data-target='#Layer 'v-on: Click = "currentuser = index" > delete < / button >
		<tr v-show="myData.length!=0">
			<td colspan="4" class="text-right">
				<button class="btn btn-danger btn-xs" v-on:click='currentUser="all"' data-toggle='modal' data-target="#Layer "> delete all < / button >
		<tr v-show="myData.length==0">
			<td colspan="4" class="text-center">
				<p class="text-muted">No data...</p>
	<div class="modal fade bs-example-modal-sm" role='dialog' id="layer">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button class="close" data-dismiss='modal'>
					<h4 class="modal-title">Are you sure to delete?</h4>
				<div class="modal-body text-right">
					<button class="btn btn-primary btn-sm" data-dismiss='modal'>cancel</button>
					<button class="btn btn-danger btn-sm" data-dismiss='modal'  v-on:click="deleteuser()">confirm</button>

	var c = new Vue({
				{name:"Zhang San",age:20},
				{name:"Li Si",age:20},
				{name:"Wang Wu",age:20},
			currentUser :-100,
		methods : {
			deleteuser :function(){
				if (this.currentUser == 'all') {
					this.myData = [];
			add : function(){
				if (this.username!=""&&this.age!=0) {


Tags: Vue JSON JQuery

Posted on Fri, 10 Jan 2020 11:10:36 -0500 by chuspy