使用vue写简单的商品管理

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style>
		
		</style>
	</head>
	<body>
		<div id="app">
			<fieldset>
				<legend>新商品信息</legend>
				<div>
					<label>名称:</label>
					<input type="text" v-model="newProduct.name"/>
				</div>
				<div>
					<label>价格:</label>
					<input type="text" v-model="newProduct.price"/>
				</div>
				<div>
					<label>类别:</label>
					<select v-model="newProduct.category">
						<option v-for="cate in categories" v-bind:value="cate">
							{{cate}}
						</option>
					</select>
					
				</div>
				<div>
					<label></label>
					<button @click="createProd">添加</button>
				</div>
			</fieldset>
			<div>
				<label>查询关键字:</label>
				<input type="text" v-model="key"/>
			</div>
			<table>
				<thead>
					<tr>
						<th>名称</th>
						<th>价格</th>
						<th>类别</th>
						<th>删除</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="(prod,index) in findProdList">
						<td>{{prod.name}}</td>
						<td>{{prod.price | priceFormat}}</td>
						<td>{{prod.category}}</td>
						<td><button @click="deletaProd(index)">删除</button></td>
					</tr>
				</tbody>
			</table>
		</div>
		
	</body>
	<script src="js/vue.js"></script>
	<script>
		var em=new Vue({
			el:'#app',
			data:{
			   key:"",
			   newProduct:{
				   name:"",price:0,category:"手机/数码"
			   },
			   categories:[
				   "手机/数码",
				   "电脑/办公",
				   "居家/家具",
				   "男装/女装",
				   "房产/汽车"
			   ],
			   productes:[
				   {name:"男士卫衣",price:100,category:"男装女装"}
			   ]
			   
			},
			filters:{
				priceFormat:function(val){
					return "$"+parseInt(val).toFixed(2)+"元";
					
				}
			},
			methods:{
				createProd:function(){
					this.productes.push(this.newProduct);
					this.newProduct={
				   name:"",price:0,category:"手机/数码"
			   }
			   
				},
				deletaProd:function(index){
					if(confirm("删除当前商品信息吗")){
						this.productes.splice(index,1)
					}
				}
			},
			computed:{
				findProdList:function(){
					var _this=this;
					return _this.productes.filter(function(prod){
						return prod.name.indexOf(_this.key)!=-1;
					})
				}
			}
		});
	</script>
</html>

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值