常用页面模板 ANTD VUE

文章展示了使用ANTDVue库创建的三种常见页面模板:空白页面、带有分页的简单表格以及包含详情弹窗的表格。在表格部分,详细说明了如何实现数据加载、分页功能以及在表格内展示详情的交互设计。
摘要由CSDN通过智能技术生成

一. 空白页面

<template>
    <div class="container" id="container">

    </div>
</template>
<script>
export default {
   name:"",
   data() {
      return {
      }
   },
   created() {
   },
   methods: {
   }
}
</script>
<style lang="less" scoped>
	.container{
		width: 100%;
		height: 100%;
	}
</style>

二. 表格

1. 简单表格,带分页

<template>
  <div class="container" id="container">
    <a-table
      :dataSource="tableData"
      :columns="tableColumns"
      :pagination="pagination"
      @change="tableChange"
      :loading="loading"
      rowKey="id"
    ></a-table>
  </div>
</template>
<script>
export default {
  name: '',
  data() {
    return {
      tableData: [], // 表格数据
      tableColumns: [], // 表格列名
      loading: false, // 表格加载效果
      pagination: {
        total: 0, // 数据总数
        current: 1, // 当前页数
        pageSize: 10, // 每页数量
        showTotal: (total) => `${total} 条数据`, // 展示总共有几条数据
        showSizeChanger: true, // 显示修改pageSize的下拉框
        pageSizeOptions: ['5', '10', '20'], // 设置pageSize的可选值,页面啊可以通过下拉框进行选择
        // eslint-disable-next-line no-return-assign
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize)
      }
    }
  },
  created() {
	  // 设置tableColumns 
	  // 通过接口请求数据,放入tableData 
  },
  methods: {
    tableChange(pagination) {
      // 表格翻页
      this.pagination = pagination
    }
  }
}
</script>
<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
}
</style>

2. 表格内详情弹窗

<template>
  <div class="container" id="container">
    <a-table
      :dataSource="tableData"
      :columns="tableColumns"
      :pagination="pagination"
      @change="tableChange"
      :loading="loading"
      rowKey="id"
    >
      <template #slot="record">
        <a-button type="link" @click="handleDetail(record)">详情</a-button>
      </template>
    </a-table>
     <!-- 弹窗内容 -->
    <a-modal
      v-model="visible"
      :title="modal.title"
      :footer="false"
      :afterClose="clearModal"
      width="50%"
    >
      <a-table
        :dataSource="modal.tableData"
        :columns="modal.tableColumns"
        :pagination="modal.pagination"
        @change="modalTableChange"
        :loading="modal.loading"
        rowKey="id"
        :scroll="{ x: false, y: 500 }"
      >
      </a-table>
    </a-modal>
  </div>
</template>
<script>
export default {
  name: '',
  data() {
    return {
      tableData: [], // 表格数据
      tableColumns: [], // 表格列名
      loading: false, // 表格加载效果
      pagination: {
        // 表格分页
        total: 0, // 数据总数
        current: 1, // 当前页数
        pageSize: 10, // 每页数量
        showTotal: (total) => `${total} 条数据`, // 展示总共有几条数据
        showSizeChanger: true, // 显示修改pageSize的下拉框
        pageSizeOptions: ['5', '10', '20'], // 设置pageSize的可选值,页面啊可以通过下拉框进行选择
        // eslint-disable-next-line no-return-assign
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize)
      },

      visible: false,
      modal: {
        title: '', // 弹窗标题
        tableData: [], // 表格数据
        tableColumns: [], // 表格列名
        loading: false, // 表格加载效果
        pagination: {
          total: 0, // 数据总数
          current: 1, // 当前页数
          pageSize: 10, // 每页数量
          showTotal: (total) => `${total} 条数据`, // 展示总共有几条数据
          showSizeChanger: true, // 显示修改pageSize的下拉框
          pageSizeOptions: ['5', '10', '20'], // 设置pageSize的可选值,页面啊可以通过下拉框进行选择
          // eslint-disable-next-line no-return-assign
          onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize)
        }
      }
    }
  },
  created() {
    this.tableColumns = [
      { title: '更多', key: 'detail', scopedSlots: { customRender: 'detail' } }
    ]
  },
  methods: {
    tableChange(pagination) {
      // 表格翻页
      this.pagination = pagination
    },
    modalTableChange(pagination) {
      // 弹窗表格翻页
      this.modal.pagination = pagination
    },
    clearModal() {
      this.modal.title = ''
      this.modal.tableData = []
      this.modal.pagination.current = 1
      this.modal.pagination.pageSize = 10
      this.modal.pagination.total = 0
    }
  }
}
</script>
<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
}
</style>

三. 表单

提交查询,重置表单,展开表单

<template>
  <div class="container" id="container">
    <div class="formBox">
      <a-form class="search-form" :form="form" @submit="handleSearch">
        <a-row :gutter="24">
          <a-col
            v-for="(formItem, i) in formList"
            :key="formItem.value"
            :span="6"
            :style="{ display: i < count ? 'block' : 'none' }"
          >
            <a-form-item :label="formItem.label">
              <a-input
                v-decorator="[formItem.value]"
                :placeholder="`请输入${formItem.label}`"
              />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24" style="text-align: right">
            <a-button type="primary" html-type="submit"> 查询 </a-button>
            <a-button style="margin-left: 8px" @click="handleReset">
              重置
            </a-button>
            <a
              style=" margin-left: 8px, font-size: 12px "
              @click="() => (expand = !expand)"
            >
              {{ expand ? '收起' : '展开' }}
              <a-icon :type="expand ? 'up' : 'down'" />
            </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
  </div>
</template>
<script>
export default {
  name: '',
  data() {
    return {
      expand: false,
      form: this.$form.createForm(this, { name: 'search-form' }),
      formList: []
    }
  },
  computed: {
    count() {
      return this.expand ? 99 : 4
    }
  },
  created() {
  	// 此处写表单项
    this.formList = [
      { label: 'a', value: 'a' },
      { label: 'b', value: 'b' }
    ]
  },
  methods: {
    handleSearch(e = undefined) {
      // 点击搜索
      if (e) {
        e.preventDefault()
        // 若有表格数据,则把表格页码回到1
        // this.pagination.current = 1
      }
      this.form.validateFields((error, values) => {
        console.log('error', error)
        console.log('values ', values)
        if (!error) {
        	// 此处写查询函数
        }
      })
    },
    handleReset() {
      // 清空表单
      this.form.resetFields()
    }
  }
}
</script>
<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
}
.search-form {
  padding: 24px 0;
}

.search-form .ant-form-item,
.modal-form .ant-form-item,
.ant-form-item {
  display: flex;
}
/deep/.search-form .ant-form-item-control-wrapper,
.modal-form .ant-form-item-control-wrapper {
  flex: 1;
}
#components-form-demo-advanced-search .ant-form {
  max-width: none;
}
.modal-form .ant-form-item {
  margin: 0;
}
/deep/.modal-form .ant-form-item-control-wrapper {
  width: 90%;
}
#components-form-demo-advanced-search .search-result-list {
  margin-top: 16px;
  border: 1px dashed #e9e9e9;
  border-radius: 6px;
  background-color: #fafafa;
  min-height: 200px;
  text-align: center;
  padding-top: 80px;
}
</style>

引用\[3\]: Ant-design-Vue是Ant Design唯一推荐的Vue UI组件库,实际上是Ant Design的Vue实现。组件的样式与Ant Design同步,组件的html结构和css样式一致。使用它,我们发现它可以称为VUE组件库和开发方案的少数完整集成项目之一。根据引用\[1\]和引用\[2\]的描述,当使用getContainer属性指定容器时,可以将整个页面的容器指定为a-collapse组件。这样,在点击锚点属性时,后面的导航页会增加一个。为了规范导航页的增加模式,可以在watch中加入判断条件,比如判断newVal.hash是否存在,如果不存在则不增加导航页。所以,如果你想在Ant Design Vue中注册页面,你可以使用Ant-design-Vue提供的组件和开发方案来实现。 #### 引用[.reference_title] - *1* *2* [antd vue Anchor getContainer属性踩坑](https://blog.csdn.net/a2690656046/article/details/124667933)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [antd适合vue使用吗,antd vue pro](https://blog.csdn.net/weixin_31299543/article/details/118119265)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值