Vue_(基础)商品管理-demo
实现对商品的增加、删除、数量的修改功能
删除商品可选择直接删除当前商品、删除选中商品、删除所有商品
添加商品时会自动添加日期字段
商品的属性
goods : {
id : '',
name : '',
price : '',
num : '',
type : '',
addDate : ''
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : '',
addDate : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
],
colNum : 8,
delArray:[] //删除选中的索引
},
methods : {
addGoods(){
var d = new Date();
var y = d.getFullYear();
var m = d.getMonth()+1;
var day =d.getDate()<10?'0'+d.getDate() : d.getDate();
var myDate = y+ '-' + m +'-'+day; this.goods.addDate = myDate ;
this.goodsArray.push(this.goods);
this.goods = {};
},
delGoods(index){
this.goodsArray.splice(index, 1);
},
clearGoodsArray(){
this.goodsArray = [];
},
delSelected(){
this.delArray.sort((a, b)=>{
return a - b;
}); for(var i=0; i<this.delArray.length; i++){
this.goodsArray.splice(this.delArray[i] - i, 1);
}
this.delArray = [];
}
}
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
.header{
margin: 10px;
border: 1px solid gray;
}
.header .title{
color: rgb(53, 73, 93);
background: rgb(65, 184, 131);
}
.logo{
position: relative;
top: 12px;
} .form-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.form-warp .content{
line-height: 35px;
}
.form-warp input{
width: 150px;
height: 18px;
}
.form-warp select{
width: 154px;
height: 24px;
} .sub-title{
color: rgb(65, 184, 131);
background: rgb(53, 73, 93);
} .table-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.table-warp th{
width: 80px;
color: #FFF;
background-color: rgb(53, 73, 93);
}
.table-warp a{
text-decoration: none;
}
.clear-btn{
text-align: right;
padding-right: 10px;
}
.fontColor{
color: gray;
}
.myBackgounrdColor{
background: rgb(65, 184, 131);
}
.myFontSize{
font-size: 200px;
}
</style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<h2 :class="{fontColor : goodsArray.length <= 0}" class="sub-title">商品列表</h2>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
<th>入库日期</th>
<th>删除</th>
<th>选择</th>
</tr>
<tr>
<td :colspan="colNum" height="150px" v-show="goodsArray.length <= 0">暂无商品</td>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td style="display: flex;">
<a style="flex: 0.5;" href="#" @click.prevent="item.num = item.num-- <= 0 ? 0 : item.num--">-</a>
{{item.num}}
<a style="flex: 0.5;" href="#" @click.prevent="item.num++">+</a>
</td> <td>{{item.type}}</td>
<td>{{item.addDate }}</td>
<td>
<button @click="delGoods(index)">删除</button>
</td>
<td>
<input type="checkbox" :value="index" v-model="delArray"/>
</td>
</tr>
</table>
</div>
<div class="clear-btn">
<a href="#" @click.prevent="delSelected" v-show="delArray.length > 0">删除选中</a>
<a href="#" @click.prevent="clearGoodsArray" v-show="goodsArray.length > 0">清空全部</a>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
Learn
一、创建页面与部分属性
二、添加商品
三、给项目添加样式
四、删除商品与提示
五、删除用户选中商品
六、修改商品数量 增加入库信息属性
项目结构
一、创建页面与部分属性
商品头部数据域
data : {
imgUrl : '../res/images/',
imgName : 'logo.png'
}
商品头部样式
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png'
},
methods : { }
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
} </style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<!--显示 表格-->
<div class="table-wrap"></div>
</div>
</body>
</html>
Gary_VueShop.html
添加商品的部分属性
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : '',
},
goodsType : ['零食', '电子产品', '生活用品']
}
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : '',
},
goodsType : ['零食', '电子产品', '生活用品']
}
methods : { }
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
} </style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<!--显示 表格-->
<div class="table-wrap"></div>
</div>
</body>
</html>
Gary_VueShop.html
二、添加商品
在Vue数据域中添加商品实例
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
在body中添加列出商品详情
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
</tr>
</table>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
]
},
methods : { }
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
} </style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button>确认添加</button>
<button>重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<div class="title">商品列表</div>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
给"确认添加"和"重置信息"绑定事件响应
methods : {
addGoods(){
this.goodsArray.push(this.goods);
this.goods = {};
}
}
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
]
},
methods : {
addGoods(){
this.goodsArray.push(this.goods);
this.goods = {};
}
}
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
} </style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<div class="title">商品列表</div>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
三、给项目添加样式
直接在<style type="text/css"></style>中为项目添加样式
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
.header{
margin: 10px;
border: 1px solid gray;
}
.header .title{
color: rgb(53, 73, 93);
background: rgb(65, 184, 131);
}
.logo{
position: relative;
top: 12px;
} .form-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.form-warp .content{
line-height: 35px;
}
.form-warp input{
width: 150px;
height: 18px;
}
.form-warp select{
width: 154px;
height: 24px;
} .sub-title{
color: rgb(65, 184, 131);
background: rgb(53, 73, 93);
} .table-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.table-warp th{
width: 80px;
color: #FFF;
background-color: rgb(53, 73, 93);
}
.table-warp a{
text-decoration: none;
}
.clear-btn{
text-align: right;
padding-right: 10px;
}
.fontColor{
color: gray;
}
.myBackgounrdColor{
background: rgb(65, 184, 131);
}
.myFontSize{
font-size: 200px;
}
</style>
CSS
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
]
},
methods : {
addGoods(){
this.goodsArray.push(this.goods);
this.goods = {};
}
}
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
.header{
margin: 10px;
border: 1px solid gray;
}
.header .title{
color: rgb(53, 73, 93);
background: rgb(65, 184, 131);
}
.logo{
position: relative;
top: 12px;
} .form-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.form-warp .content{
line-height: 35px;
}
.form-warp input{
width: 150px;
height: 18px;
}
.form-warp select{
width: 154px;
height: 24px;
} .sub-title{
color: rgb(65, 184, 131);
background: rgb(53, 73, 93);
} .table-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.table-warp th{
width: 80px;
color: #FFF;
background-color: rgb(53, 73, 93);
}
.table-warp a{
text-decoration: none;
}
.clear-btn{
text-align: right;
padding-right: 10px;
}
.fontColor{
color: gray;
}
.myBackgounrdColor{
background: rgb(65, 184, 131);
}
.myFontSize{
font-size: 200px;
}
</style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<div class="title">商品列表</div>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
四、删除商品与提示
添加删除商品button放入表单个中
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
<th>删除</th>
</tr>
<tr>
<td :colspan="colNum" height="150px" v-show="goodsArray.length <= 0">暂无商品</td>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
<td>
<button @click="delGoods(index)">删除</button>
</td>
</tr>
</table>
添加清空全部商品按钮点击控件
使用@click.prevent可以阻止删除<a>标签默认跳转事件,使用v-show="goodsArray.length > 0判断当商品个数大于0的时候才将次链接显示出来
<div>
<a href="#" @click.prevent="clearGoodsArray" v-show="goodsArray.length > 0">清空全部</a>
</div>
添加绑定删除单个商品和全部商品的函数
methods : {
addGoods(){
this.goodsArray.push(this.goods);
this.goods = {};
},
delGoods(index){
this.goodsArray.splice(index, 1);
},
clearGoodsArray(){
this.goodsArray = [];
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
],
colNum : 8
},
methods : {
addGoods(){
this.goodsArray.push(this.goods);
this.goods = {};
},
delGoods(index){
this.goodsArray.splice(index, 1);
},
clearGoodsArray(){
this.goodsArray = [];
}
}
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
.header{
margin: 10px;
border: 1px solid gray;
}
.header .title{
color: rgb(53, 73, 93);
background: rgb(65, 184, 131);
}
.logo{
position: relative;
top: 12px;
} .form-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.form-warp .content{
line-height: 35px;
}
.form-warp input{
width: 150px;
height: 18px;
}
.form-warp select{
width: 154px;
height: 24px;
} .sub-title{
color: rgb(65, 184, 131);
background: rgb(53, 73, 93);
} .table-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.table-warp th{
width: 80px;
color: #FFF;
background-color: rgb(53, 73, 93);
}
.table-warp a{
text-decoration: none;
}
.clear-btn{
text-align: right;
padding-right: 10px;
}
.fontColor{
color: gray;
}
.myBackgounrdColor{
background: rgb(65, 184, 131);
}
.myFontSize{
font-size: 200px;
}
</style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<h2 :class="{fontColor : goodsArray.length <= 0}" class="sub-title">商品列表</h2>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
<th>删除</th>
</tr>
<tr>
<td :colspan="colNum" height="150px" v-show="goodsArray.length <= 0">暂无商品</td>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
<td>
<button @click="delGoods(index)">删除</button>
</td>
</tr>
</table>
</div>
<div>
<a href="#" @click.prevent="clearGoodsArray" v-show="goodsArray.length > 0">清空全部</a>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
五、删除用户选中商品
使用input来存放选中商品的索引
在Vue数据域中添加delArray数据
delArray:[] //删除选中的索引
<td>
<input type="checkbox" :value="index" v-model="delArray"/>
</td>
{{delArray}}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
],
colNum : 8,
delArray:[] //删除选中的索引
},
methods : {
addGoods(){
this.goodsArray.push(this.goods);
this.goods = {};
},
delGoods(index){
this.goodsArray.splice(index, 1);
},
clearGoodsArray(){
this.goodsArray = [];
}
}
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
.header{
margin: 10px;
border: 1px solid gray;
}
.header .title{
color: rgb(53, 73, 93);
background: rgb(65, 184, 131);
}
.logo{
position: relative;
top: 12px;
} .form-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.form-warp .content{
line-height: 35px;
}
.form-warp input{
width: 150px;
height: 18px;
}
.form-warp select{
width: 154px;
height: 24px;
} .sub-title{
color: rgb(65, 184, 131);
background: rgb(53, 73, 93);
} .table-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.table-warp th{
width: 80px;
color: #FFF;
background-color: rgb(53, 73, 93);
}
.table-warp a{
text-decoration: none;
}
.clear-btn{
text-align: right;
padding-right: 10px;
}
.fontColor{
color: gray;
}
.myBackgounrdColor{
background: rgb(65, 184, 131);
}
.myFontSize{
font-size: 200px;
}
</style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<h2 :class="{fontColor : goodsArray.length <= 0}" class="sub-title">商品列表</h2>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
<th>删除</th>
<th>选择</th>
</tr>
<tr>
<td :colspan="colNum" height="150px" v-show="goodsArray.length <= 0">暂无商品</td>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
<td>
<button @click="delGoods(index)">删除</button>
</td>
<td>
<input type="checkbox" :value="index" v-model="delArray"/>
</td>
{{delArray}}
</tr>
</table>
</div>
<div>
<a href="#" @click.prevent="clearGoodsArray" v-show="goodsArray.length > 0">清空全部</a>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
为方便点击清空全部与删除选中索引,可以把清空全部按钮放置在右下角
添加选中商品链接
<div class="clear-btn">
<a href="#" @click.prevent="delSelected" v-show="delArray.length > 0">删除选中</a>
<a href="#" @click.prevent="clearGoodsArray" v-show="goodsArray.length > 0">清空全部</a>
</div>
delSelected(){
this.delArray.sort((a, b)=>{
return a - b;
}); for(var i=0; i<this.delArray.length; i++){
this.goodsArray.splice(this.delArray[i] - i, 1);
}
this.delArray = [];
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
],
colNum : 8,
delArray:[] //删除选中的索引
},
methods : {
addGoods(){
this.goodsArray.push(this.goods);
this.goods = {};
},
delGoods(index){
this.goodsArray.splice(index, 1);
},
clearGoodsArray(){
this.goodsArray = [];
},
delSelected(){
this.delArray.sort((a, b)=>{
return a - b;
}); for(var i=0; i<this.delArray.length; i++){
this.goodsArray.splice(this.delArray[i] - i, 1);
}
this.delArray = [];
}
}
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
.header{
margin: 10px;
border: 1px solid gray;
}
.header .title{
color: rgb(53, 73, 93);
background: rgb(65, 184, 131);
}
.logo{
position: relative;
top: 12px;
} .form-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.form-warp .content{
line-height: 35px;
}
.form-warp input{
width: 150px;
height: 18px;
}
.form-warp select{
width: 154px;
height: 24px;
} .sub-title{
color: rgb(65, 184, 131);
background: rgb(53, 73, 93);
} .table-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.table-warp th{
width: 80px;
color: #FFF;
background-color: rgb(53, 73, 93);
}
.table-warp a{
text-decoration: none;
}
.clear-btn{
text-align: right;
padding-right: 10px;
}
.fontColor{
color: gray;
}
.myBackgounrdColor{
background: rgb(65, 184, 131);
}
.myFontSize{
font-size: 200px;
}
</style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<h2 :class="{fontColor : goodsArray.length <= 0}" class="sub-title">商品列表</h2>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
<th>删除</th>
<th>选择</th>
</tr>
<tr>
<td :colspan="colNum" height="150px" v-show="goodsArray.length <= 0">暂无商品</td>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td>{{item.num}}</td>
<td>{{item.type}}</td>
<td>
<button @click="delGoods(index)">删除</button>
</td>
<td>
<input type="checkbox" :value="index" v-model="delArray"/>
</td>
{{delArray}}
</tr>
</table>
</div>
<div class="clear-btn">
<a href="#" @click.prevent="delSelected" v-show="delArray.length > 0">删除选中</a>
<a href="#" @click.prevent="clearGoodsArray" v-show="goodsArray.length > 0">清空全部</a>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
六、修改商品数量 增加入库信息属性
直接使用@click.prevent对商品数量的修改
<td style="display: flex;">
<a style="flex: 0.5;" href="#" @click.prevent="item.num = item.num-- <= 0 ? 0 : item.num--">-</a>
{{item.num}}
<a style="flex: 0.5;" href="#" @click.prevent="item.num++">+</a>
</td>
添加商品日期字段
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : '',
addDate : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
],
colNum : 8,
delArray:[] //删除选中的索引
}
将商品信息字段添加进表格当中
<th>入库日期</th>
<td>{{item.addDate }}</td>
修改增加商品addGoods()函数
addGoods(){
var d = new Date();
var y = d.getFullYear();
var m = d.getMonth()+1;
var day =d.getDate()<10?'0'+d.getDate() : d.getDate();
var myDate = y+ '-' + m +'-'+day; this.goods.addDate = myDate ;
this.goodsArray.push(this.goods);
this.goods = {};
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gary商品管理</title>
<script type="text/javascript" src="../js/vue.js" ></script>
<script>
window.onload = () => {
let vm = new Vue({
el : '.container',
data : {
imgUrl : '../res/images/',
imgName : 'logo.png',
goods : {
id : '',
name : '',
price : '',
num : '',
type : '',
addDate : ''
},
goodsType : ['零食', '电子产品', '生活用品'],
goodsArray : [
{id : '001', name : '可乐', price : 10, num : 10, type : '零食', addDate : '2019-02-23'},
{id : '002', name : '手机', price : 1000, num : 20, type : '电子产品', addDate : '2019-02-24'},
{id : '003', name : '毛巾', price : 5, num : 30, type : '生活用品', addDate : '2019-02-25'}
],
colNum : 8,
delArray:[] //删除选中的索引
},
methods : {
addGoods(){
var d = new Date();
var y = d.getFullYear();
var m = d.getMonth()+1;
var day =d.getDate()<10?'0'+d.getDate() : d.getDate();
var myDate = y+ '-' + m +'-'+day; this.goods.addDate = myDate ;
this.goodsArray.push(this.goods);
this.goods = {};
},
delGoods(index){
this.goodsArray.splice(index, 1);
},
clearGoodsArray(){
this.goodsArray = [];
},
delSelected(){
this.delArray.sort((a, b)=>{
return a - b;
}); for(var i=0; i<this.delArray.length; i++){
this.goodsArray.splice(this.delArray[i] - i, 1);
}
this.delArray = [];
}
}
});
}
</script>
<style type="text/css">
.container{
margin: 0 auto;
text-align: center;
width: 1000px;
border: 2px solid gray;
}
.header{
margin: 10px;
border: 1px solid gray;
}
.header .title{
color: rgb(53, 73, 93);
background: rgb(65, 184, 131);
}
.logo{
position: relative;
top: 12px;
} .form-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.form-warp .content{
line-height: 35px;
}
.form-warp input{
width: 150px;
height: 18px;
}
.form-warp select{
width: 154px;
height: 24px;
} .sub-title{
color: rgb(65, 184, 131);
background: rgb(53, 73, 93);
} .table-warp{
margin: 10px;
padding-bottom: 10px;
border: 1px solid gray;
}
.table-warp th{
width: 80px;
color: #FFF;
background-color: rgb(53, 73, 93);
}
.table-warp a{
text-decoration: none;
}
.clear-btn{
text-align: right;
padding-right: 10px;
}
.fontColor{
color: gray;
}
.myBackgounrdColor{
background: rgb(65, 184, 131);
}
.myFontSize{
font-size: 200px;
}
</style>
</head>
<body>
<div class="container">
<!--有logo和title-->
<div class="header">
<img :src="imgUrl + imgName" class="logo" height="80px" />
<h1 class="title">Gary_商品管理</h1>
</div>
<!--输入部分input-->
<div class="form-warp"></div>
<div class = "title">添加商品</div>
<div class="content">
商品编号:<input type="text" placeholder="请输入商品编号" v-model="goods.id"/><br />
商品名称:<input type="text" placeholder="请输入商品名称" v-model="goods.name"/><br />
商品价格:<input type="text" placeholder="请输入商品价格" v-model="goods.price"/><br />
商品数量:<input type="text" placeholder="请输入商品数量" v-model="goods.num"/><br />
商品类型:<select v-model="goods.type">
<option value=""> -- 选择商品类型 --</option>
<option v-for="type in goodsType">{{type}}</option>
</select>
</div>
<div class="form-btn"></div>
<button @click="addGoods">确认添加</button>
<button @click="goods = {}">重置信息</button>
<!--显示 表格-->
<div class="table-wrap">
<h2 :class="{fontColor : goodsArray.length <= 0}" class="sub-title">商品列表</h2>
<div class="content">
<table border="1" align="center" cellspacing="" cellpadding="">
<tr>
<th>序号</th>
<th>编号</th>
<th>名称</th>
<th>价格</th>
<th>数量</th>
<th>类型</th>
<th>入库日期</th>
<th>删除</th>
<th>选择</th>
</tr>
<tr>
<td :colspan="colNum" height="150px" v-show="goodsArray.length <= 0">暂无商品</td>
</tr>
<tr v-for="(item, index) in goodsArray" :key="item.id">
<td>{{index}}</td>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>{{item.price}}</td>
<td style="display: flex;">
<a style="flex: 0.5;" href="#" @click.prevent="item.num = item.num-- <= 0 ? 0 : item.num--">-</a>
{{item.num}}
<a style="flex: 0.5;" href="#" @click.prevent="item.num++">+</a>
</td> <td>{{item.type}}</td>
<td>{{item.addDate }}</td>
<td>
<button @click="delGoods(index)">删除</button>
</td>
<td>
<input type="checkbox" :value="index" v-model="delArray"/>
</td>
</tr>
</table>
</div>
<div class="clear-btn">
<a href="#" @click.prevent="delSelected" v-show="delArray.length > 0">删除选中</a>
<a href="#" @click.prevent="clearGoodsArray" v-show="goodsArray.length > 0">清空全部</a>
</div>
</div>
</div>
</body>
</html>
Gary_VueShop.html
Vue_(基础)商品管理-demo的更多相关文章
- Super超级ERP系统---(3)基础信息管理--商品管理
商品管理主要包括商品的添加,修改,维护商品所在分类,单位,供应商,品牌,名称,价格,尺寸,规格等属性的维护. 1.商品添加 2.商品列表展示 商品列表界面左侧商品分类,右侧是商品信息
- C#开发微信门户及应用(23)-微信小店商品管理接口的封装和测试
在上篇<C#开发微信门户及应用(22)-微信小店的开发和使用>里面介绍了一些微信小店的基础知识,以及对应的对象模型,本篇继续微信小店的主题,介绍其中API接口的封装和测试使用.微信小店的相 ...
- SQL Server 【附】创建"商品管理数据库"、"学生选课数据库"的SQL语句
附:(创建“商品管理数据库”的SQL语句) --建立"商品管理数据库"数据库-- create database 商品管理数据库 on(name='商品管理数据库_m', file ...
- mvc 权限管理 demo
http://blog.csdn.net/zht666/article/details/8529646 new http://www.cnblogs.com/fengxing/archive/2012 ...
- vue实现图书管理demo
年后公司的项目要求用到vue.js知识,我angular没有学,node.js和react也只是了解了一点点,所以学起来比较困难.如果你想学vue.js的知识,推荐网址:http://vuejs.or ...
- Vue小案例 之 商品管理------学习过滤器 使用过滤器处理日期的格式
代码学习过滤器 过滤器介绍:过滤模型数据,在数据显示前做预处理操作: 内置过滤器:在1.x中,Vue提供了内置过滤器,但是在2.x中已经完全废除: 解决办法: (1)使用第三方库来替代1.x中的内置过 ...
- 【一起学源码-微服务】Hystrix 源码一:Hystrix基础原理与Demo搭建
说明 原创不易,如若转载 请标明来源! 欢迎关注本人微信公众号:壹枝花算不算浪漫 更多内容也可查看本人博客:一枝花算不算浪漫 前言 前情回顾 上一个系列文章讲解了Feign的源码,主要是Feign动态 ...
- 「超市管理系统——商品管理」 · Java Swing + MySQL JDBC开发
项目下载:https://download.csdn.net/download/weixin_44893902/13715024 1.9元付费赞助下载:https://download.csdn.ne ...
- EasyUI+MVC+EF简单用户管理Demo(问题及解决)
写在前面 iframe-src EntityFramework版本 connectionStrings View.Action.页面跳转 EasyUI中DataGrid绑定 新增.修改和删除数据 效果 ...
随机推荐
- JSON函数表1
jsoncpp 主要包含三个class:Value.Reader.Writer.注意Json::Value 只能处理 ANSI 类型的字符串,如果 C++ 程序是用 Unicode 编码的,最好加一个 ...
- winfrom 点击按钮button弹框显示颜色集
1.窗体托一个按钮button: 2.单击事件: private void btnForeColor_Click(object sender, EventArgs e) { using (ColorD ...
- visual studio2015 搭建pro*c开发编译环境
关于pro*c是什么,这里不做介绍,主要说明如何在vs2015里面开发pro*c程序,并编译exe执行文件 一.vs2015环境配置 1.新建一个空的vc++项目,如下图 2.右击项目属性,添加相关的 ...
- AxMath_V2.5.0.0安装和激活
目录 1. 相关推荐 2. 按 3. AxMath 功能与特色 4. 软件介绍 4.1. 编辑与排版 4.2. 科学计算功能 4.3. 输出与发布 4.4. 运行环境 4.5. 破解说明 5. 安装步 ...
- Odoo的 数据添加修改删除代码和对应的方式
完整的可用命令如下: (0, _ , {‘field’: value})新建一条记录并将其与之关联 (1, id, {‘field’: value})更新已关联记录的值 (2, id, _)移除关联并 ...
- How to mount remote Windows shares
Contents Required packages Basic method Better Method Even-better method Yet Another Even-better m ...
- Kernel boot options
There are three ways to pass options to the kernel and thus control its behavior: When building the ...
- MySQL连表查询练习题
1.建库 库名:linux50 字符集:utf8 校验规则:utf8_general_ci  create database linux4 charset utf8 default collate ...
- python网络编程:socket套接字
一.socket 二.TCP服务器 三.TCP客户端 四.UDP服务器 五.UDP客户端 六.聊天的客户端 七.聊天的服务器 一.socket """ 学习网络编程 其实 ...
- Vim技巧----光标移动
w:向前移动,光标停留在下个单词词首,每次一个单词(单词中不含其他字符如:- \ = +等) W:向前移动,光标停留在下个单词词首,每次一个字符串(字符串可以含有其字符如:- \ = +等,is-a ...