Ant Design pro of vue如何使用a-list的分页设置

 找到图片中的这个位置,写一个pagination来动态配置a-list的pagination分页

 在data的return 中设置pagination的配置

 完整代码如下:

<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <a-row>
        <a-col :sm="8" :xs="24">
          <info title="植物总数量" value="1677" :bordered="true" />
        </a-col>
        <a-col :sm="8" :xs="24">
          <info title="信息完善的植物数量" value="1677" :bordered="true" />
        </a-col>
        <a-col :sm="8" :xs="24">
          <info title="信息不完善的植物数量" value="0" />
        </a-col>
      </a-row>
    </a-card>

    <a-card style="margin-top: 24px" :bordered="false" title="植物列表">
      <div slot="extra">
        <a-radio-group v-model="status" @change="statusChange">
          <a-radio-button value="all">全部</a-radio-button>
          <a-radio-button value="herbaceous">草本</a-radio-button>
          <a-radio-button value="woody">木本</a-radio-button>
          <a-radio-button value="Liana">藤本</a-radio-button>
          <a-radio-button value="Meaty">多肉</a-radio-button>
          <a-radio-button value="Lanco">兰科</a-radio-button>
          <a-radio-button value="aquatic">水生</a-radio-button>
          <a-radio-button value="perennial_root">宿根</a-radio-button>
          <a-radio-button value="fruits">水果</a-radio-button>
          <a-radio-button value="vegetables">蔬菜</a-radio-button>
        </a-radio-group>
        <a-input-search style="margin-left: 16px; width: 272px" />
      </div>

      <div class="operate">
        <a-button type="dashed" style="width: 100%" icon="plus" @click="add">添加</a-button>
      </div>

      <a-list size="large" :pagination="pagination">
        <a-list-item :key="index" v-for="(item, index) in data">
          <a-list-item-meta :description="item.description">
            <!-- 设置description多出来的省略 -->

            <a-avatar slot="avatar" size="large" shape="square" :src="item.avatar" />
            <a slot="title">{{ item.title }}</a>
          </a-list-item-meta>
          <div slot="actions">
            <a @click="edit(item)">编辑</a>
          </div>
          <div slot="actions">
            <a-dropdown>
              <!--   @click函数返回事件点击和item-->
              <a-menu slot="overlay" @click="handleMenuClick($event, item)">
                <a-menu-item ><a>详情</a></a-menu-item>
                <a-menu-item><a>删除</a></a-menu-item>
              </a-menu>
              <a>更多<a-icon type="down" /></a>
            </a-dropdown>
          </div>
          <div class="list-content">
            <div class="list-content-item">
              <span>录入时间</span>
              <p>{{ item.startAt }}</p>
            </div>
            <!-- <div class="list-content-item">
              <a-progress
                :percent="item.progress.value"
                :status="!item.progress.status ? null : item.progress.status"
                style="width: 180px"
              />
            </div> -->
          </div>
        </a-list-item>
      </a-list>
    </a-card>
  </page-header-wrapper>
</template>

<script>
// 演示如何使用 this.$dialog 封装 modal 组件
// 如果要引入上一级目录的文件,需要使用 @/views/experiment_views/experiment_plant_data.vue
// D:\ant_design\ant-design-vue-pro\src\views\list\modules\TaskForm.vue
import TaskForm from '@/views/list/modules/TaskForm.vue'
import Info from '@/views/list/components/Info'
import { getPlantAllList } from '@/api/plantdata'
const data = []

export default {
  name: 'StandardList',
  components: {
    TaskForm,
    Info,
  },

  data() {
    return {
      data,
      status: 'all',
      pagination: {
        showSizeChanger: true,
        showQuickJumper: true,
        pageSizeOptions: ['5', '10', '20', '30'],
        total: 50,
        // 设置页面变化时的回调,调用methods中的onChange方法
        onChange: this.onChange,
        // 设置每页显示条数变化时的回调
        onShowSizeChange: this.onShowSizeChange,
      },
    }
  },
  created() {
    this.Paging_request_data(1, 5)
  },

  methods: {
    handleMenuClick(e, item) {
      console.log('click', e, item)
      if (e.key === 'item_0') {
          window.open(item.plant_detail_link)
      } else if (e.key === 'item_1') {
        this.$confirm({
          title: '确定删除吗?',
          content: '删除后无法恢复',
          okText: '确定',
          okType: 'danger',
          cancelText: '取消',
          onOk() {
            console.log('OK')
          },
          onCancel() {
            console.log('Cancel')
          },
        })
      }
    },
    // 分页请求数据
    Paging_request_data(currentPage, pageSize) {
      // 设置请求参数
      const params = {
        page: currentPage,
        pageSize: pageSize,
      }
      // 调用接口
      getPlantAllList(params).then((res) => {
        // 设置数据

        this.data = res.data
        this.pagination.total = res.data_total
      })
    },

    // 监听status的变化
    statusChange(e) {
      console.log(e.target.value)
      this.status = e.target.value
    },

    // 页面变化时的回调
    onShowSizeChange(current, size) {
      this.pagination.pageSize = size
      this.Paging_request_data(current, size)
    },
    onChange(page, pageSize) {
      // console.log(page, pageSize)
      this.Paging_request_data(page, pageSize)
    },
    add() {
      this.$dialog(
        TaskForm,
        // component props
        {
          record: {},
          on: {
            ok() {
              console.log('ok 回调')
            },
            cancel() {
              console.log('cancel 回调')
            },
            close() {
              console.log('modal close 回调')
            },
          },
        },
        // modal props
        {
          title: '新增',
          width: 700,
          centered: true,
          maskClosable: false,
        }
      )
    },
    edit(record) {
      console.log('record', record)
      this.$dialog(
        TaskForm,
        // component props
        {
          record,
          on: {
            ok() {
              console.log('ok 回调')
            },
            cancel() {
              console.log('cancel 回调')
            },
            close() {
              console.log('modal close 回调')
            },
          },
        },
        // modal props
        {
          title: '操作',
          width: 700,
          centered: true,
          maskClosable: false,
        }
      )
    },
  },
}
</script>

<style lang="less" scoped>

.ant-avatar-lg {
  width: 48px;
  height: 48px;
  line-height: 48px;
}

.list-content-item {
  color: rgba(0, 0, 0, 0.45);
  display: inline-block;
  vertical-align: middle;
  font-size: 14px;
  margin-left: 40px;
  span {
    line-height: 20px;
  }
  p {
    margin-top: 4px;
    margin-bottom: 0;
    line-height: 22px;
  }
}
</style>

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Vue-Quill-Editor 在 Vue 中结合 Ant Design,你可以按照以下步骤操作: 1. 首先,通过 npm 或 yarn 安装 Vue-Quill-Editor: ``` npm install vue-quill-editor ``` 2. 在你的 Vue 组件中,引入 Vue-Quill-Editor 和 Ant Design 的样式文件: ```javascript import 'quill/dist/quill.snow.css'; import { Form, Input, Button } from 'ant-design-vue'; import { VueQuillEditor } from 'vue-quill-editor'; ``` 3. 在 Vue 组件的 `components` 属性中注册 VueQuillEditor 组件: ```javascript components: { VueQuillEditor, // 其他组件 }, ``` 4. 在模板中使用 VueQuillEditor,可以通过 `v-model` 双向绑定实现富文本编辑器的内容获取和设置: ```html <template> <div> <vue-quill-editor v-model="content" /> <!--其他表单元素--> </div> </template> ``` 5. 如果需要将富文本编辑器嵌入到 Ant Design 的表单中,可以使用 `Form.Item` 组件包裹: ```html <template> <div> <a-form :form="form"> <a-form-item label="内容"> <vue-quill-editor v-model="content" /> </a-form-item> <!--其他表单元素--> <a-form-item> <a-button type="primary" @click="submitForm">提交</a-button> </a-form-item> </a-form> </div> </template> ``` 6. 在 Vue 组件的 `data` 属性中定义 `content` 数据,并在需要提交表单时获取 `content` 的值: ```javascript data() { return { content: '', // 其他表单数据 }; }, methods: { submitForm() { const formData = { content: this.content, // 其他表单数据 }; console.log(formData); // 提交表单逻辑 }, }, ``` 这样,你就可以在 Vue使用 Vue-Quill-Editor 结合 Ant Design 实现富文本编辑器了。记得根据实际需要进行样式和功能的定制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值