欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue中iview状态切换

程序员文章站 2022-07-14 08:45:51
...
export default {
        data () {
            return {
                columns1: [
                    {
                        title: '编号',
                        key: 'id'
                    },
                    {
                        title: '姓名',
                        key: 'name'
                    },
					{
						title:'图片',
						key:'imgs',
						render:(h,obj)=>{
							return h('img',{
								attrs:{
									src:obj.row.imgs
								},
								style:{
									width:'100px'
								}
							})
						}
					},
					{
						title:'状态',
						key:'static',
						render:(h,obj)=>{
							let btnType = 'primary';
							if (obj.row.static == 0) {
							    btnType = 'default';
							}
							return h('Button',{
								props:{
									type:btnType,
									size:'small'
								},
								on:{
									click:()=>{
										let status_text = '启用';
										let isstatic = 1;
										if (obj.row.static == 1) {
										    status_text = '禁用';
										    isstatic = 2;
										}
										this.$Modal.confirm({
										    title:'提示',
										    content:"确定要"+status_text+'此账户吗',
										    onOk: () => {
												this.list();
										        this.statics(obj.row.id);
										    }
										});
									}
								}
							},obj.row.static==1?'正常':'禁止')
						}
					},
					{
					    title: '注册时间',
					    key: 'time',
						
					},
					
                ],
                
				data1:[]
            }
        },
		mounted() {
			this.list();
		},
		methods:{
			async list(){
				let res=await this.$api.user.lists();
				if(res){
					this.data1=res.data;
					console.log(this.data1);
				}
			},
			async statics(id){			//状态切换,这里的id是传入的
				let res=await this.$api.user.statics({id});
				if(res){
					this.list();
					this.$Message.success('操作成功');
				}
			}
			
		}
		
    }