<html>
<head>
<meta charset="utf-8"/>
<script src="https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js">script>
<script src="https://cdn.bootcss.com/vue/2.5.22/vue.min.js">script>
<style type="text/css">
td{
border:1px solid #000;
}
style>
head>
<body>
<div id="app">
<table id="productListTable">
<thead>
<tr>
<th>商品名称th>
<th>数量th>
<th>操作th>
tr>
thead>
<tbody>
<tr v-for="product in products">
<td>{{product.productName}}td>
<td>{{product.nums}}td>
<td>
<a href="#nowhere" @click="edit(product)">编辑a>
<a href="#nowhere" @click="deleteProduct(product.id)">删除a>
td>
tr>
<tr>
<td colspan="3">
商品名称:
<input type="text" v-model="product4Add.productName" />
<br>
数量:
<input type="number" v-model="product4Add.nums" />
<br>
<button type="button" v-on:click="add">增加button>
td>
tr>
tbody>
table>
<script type="text/javascript">
$("#div4Update").hide();
//Model
var data = {
products: [
{ id: 1, productName: '袜子', nums: 15},
{ id: 2, productName: '羊毛衫', nums: 20},
{ id: 3, productName: '雪纺衫', nums: 24},
{ id: 4, productName: '高跟鞋', nums: 30}
],
product4Add: { id: 0, productName: '', nums: '0'},
};
var maxId = 5;
for (var i=0;i<data.products.length;i++){
if (data.products[i].id > maxId)
maxId= this.products[i].id;
}
//ViewModel
var vue = new Vue({
el: '#app',
data: data,
methods: {
add: function (event) {
maxId++;
this.product4Add.id = maxId;
if(this.product4Add.productName.length==0)
this.product4Add.productName = "product#"+this.product4Add.id;
//将对象加入到数组
this.products.push(this.product4Add);
this.product4Add = { id: 0, productName: '', nums: '0'}
},
}
});
script>
body>
html>
同样,这也是教程:Vue2.x案例之商品增删改查的实现的前端界面,此处只留了增加功能,如需要其他功能请自行看教程。
a. 打开cdn搜索网站(https://www.bootcdn.cn),搜索Bootstrap(其实第一个就是)
b. 点击,找一个版本(此处使用3.3.7版本),复制这一行:
c. 粘贴到在head标签里,引入bootstrap:
a. 删除之前的样式:
<style type="text/css">
td{
border:1px solid #000;
}
style>
b. 在Bootstrap中文官网(https://v3.bootcss.com/css) 查找Bootstrap样式
c. 找一个自己喜欢的表格样式,在table标签添加类即可:
a. 修改后为: