iview-admin 之操作按钮,弹出提交表单

本文介绍了如何在Vue.js应用中使用Modal组件进行表单设置和验证,包括设置汇率的输入框,利用Form及FormItem进行数据绑定和规则验证。当表单验证失败时,会取消loading状态并重新加载。点击确定按钮后,通过axios发送POST请求进行数据提交,并展示响应结果。同时展示了如何在表格中实现编辑和删除操作,包括使用i-switch开关组件和自定义渲染操作列。
摘要由CSDN通过智能技术生成

参考
https://blog.csdn.net/u011611479/article/details/111412697 操作列
https://blog.csdn.net/Dong8508/article/details/81875620 弹出表单

弹出表单

<template>			
	<Button type="primary" @click="modal = true">设置汇率</Button>
	<Modal
		v-model="modal"
		title="设置汇率"
		:loading="loading"
		@on-ok="ok"
		@on-cancel="cancel">
		<Form ref="setGold" :model="setForm" :rules="rules">
			<FormItem prop="rate">
				<Row>
					<Col span="6">
						<div style="margin-top:2px">请输入设置的汇率:</div>
					</Col>
					<Col span="8">
						<Input v-model="setForm.rate" placeholder="请输入设置的汇率"></Input>
					</Col>									 
				</Row>
			</formItem>	
		</Form>		
	</Modal>
</template>

<script>
export default{
	data(){
	return {
		modal: false,
		loading:true,
		setForm:{rate:''},
		rules: {
			rate: [
				{ required: true, message: '汇率不能为空', trigger: 'blur' },
			    { type: 'string',pattern:/^[0-9]*$/, message:'汇率格式不正确', trigger:'blur'},
			],     
		}
	}
	},
	mounted(){
	 
	},
	methods:{
		async ok() {
			this.$refs.setGold.validate( async(valid) => {
				if (valid) {
					let  res =await this.$ajax.post('/xx/xx',{});
					if(res.cd == 0){
						//doSomething..
					}else{
						this.$Message.info(res.msg);
					}
				}else{
		            //对话框校验失败,取消loading状态    
					this.loading=false;
					setTimeout(() => {
					  this.$nextTick(() => {
		                    this.loading = true;
		              });
					}, 100);
				}
			})   
		},
		cancel () {
		    //取消后,重置表单
			this.$refs['setGold'].resetFields();
		}
	 
	},
	 
}
</script>

操作列 (编辑删除按钮,图片,开关按钮)
在这里插入图片描述

columns: [
    { title: '缩略图',
      key: 'thumb',
      minWidth: 60,
      render: (h, params) => {
        return h('div', [
          h('img', {
            attrs: {
              src: params.row.thumb
            },
            style: {
              width: '50px',
              height: '50px'
            }
          }, 'div')
        ])
      } },
    { title: '分类', key: 'category_name', minWidth: 120 },
    { title: '上架',
      key: 'id',
      minWidth: 80,
      render: (h, params) => {
        return h('div', [
          h('i-switch', {
            props: {
              size: 'large',
              type: 'primary',
              value: true // 控制开关的打开或关闭状态,官网文档属性是value
            },
            scopedSlots: {
              open: () => h('span', '上架'),
              close: () => h('span', '下架')
            },
            on: {
              'on-change': (value) => { // 触发事件是on-change,用双引号括起来,
                this.switch(params.index) // params.index是拿到table的行序列,可以取到对应的表格值
              }
            }
          }, '上架')
        ])
      } },
    { title: '创建时间', key: 'created_time', minWidth: 120, sortable: true, sortType: 'desc' },
    { title: '操作',
      key: 'action',
      align: 'center',
      width: 200,
      fixed: 'right',
      render: (h, params) => {
        return h('div', [
          h(
            'Button',
            {
              props: {
                type: 'primary',
                size: 'small',
                icon: 'ios-create-outline'
              },
              style: {
                marginRight: '5px'
              },
              on: {
                click: () => {
                  this.edit(params.row)
                }
              }
            },
            '编辑'
          ),
          h(
            'Button',
            {
              props: {
                type: 'error',
                size: 'small',
                icon: 'md-trash'
              },
              on: {
                click: () => {
                  this.remove(params.row)
                }
              }
            },
            '删除'
          )
        ])
      }
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值