vue动态数据交互+过滤器demo

动态数据交互+过滤器demo

网络请求:axios  

window.onload=function(){
//	var vm=new Vue(...)
	new Vue({
		el:'#my',		
		data:{
			name:112
			lists:[
				/*{'name':'包包','state':'未采购'},
				{'name':'衣服','state':'已采购'},
				{'name':'手机','state':'未采购'}*/
			]
		},
		mounted:function(){
			this.getList();
		}
		methods:{
			add:function(){
				if(this.name=="") return;
				this.lists.unshift({
					{name:this.name,state:'未采购'}
				});
				this.name='';
			},
			del:function(i){
				this.lists.splice(i,1);				
			},
			getList:function(){
				//如果用了var vm=new Vue()这里可以注释
				var self=this;
				axios({
					method:'get',
					url:'这里填写接口地址',					
				}).then(function(res){
					console.log(res);
					if(res.data.code=='200'){
						if(res.data.result && res.data.result.length>0){
								self.lists=res.data.result;
						}
					}
					
				}).catch(function(error){
					console.log(error)
				})
			}
		},
		filters:{//过滤器
			stateFilter:function(type){
				if(type=='未采购'){
					return "商品未采购";
				}else if(type=="已采购"){
					return "商品已经采购,等待发货";
				}else{
					return type;
				}
			}
		}
	})
	
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值