<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      AntDesign-Vue Table 查詢與分頁

      前言

      之前的增刪改查小 Demo 已經快要進行到最后一步了,這節的任務是將請求數據的方式改為 分頁,并且增加 分頁條件查詢 的功能。

      頁面布局

      <a-table
          :data-source="dataSource"
          :columns="columns"
          :pagination="pagination"
      >
      <!-- ↑ pagination 是分頁功能,傳入一個對象 -->
        <!-- ↓ 為 a-table 組件添加個表頭,里面有一個輸入框和一個按鈕 -->
        <template #title>
          <div>
            <div>
              <!-- 為輸入框綁定事件 -->
              <a-input :bordered="false" placeholder="請輸入水果名稱" @keydown.enter="fnc_search" id="search">
              </a-input>
              <!-- 為按鈕綁定事件 -->
              <a-button @click="fnc_search">
                <!-- ↓ 一個放大鏡按鈕 -->
                <SearchOutlined></SearchOutlined>
              </a-button>
            </div>
            <!-- 在表格中添加數據的按鈕,和這篇文章沒關系 -->
            <a-button @click="showAddModal">添加</a-button>
          </div>
        </template>
        <!-- ↓ 顯示圖片的 template -->
        <template v-slot:bodyCell="{ column, record, index}">
          <template v-if="column.dataIndex === 'pic'">
            <img :src="record.avatar" @click="checkInfo(record, index)"/>
          </template>
        </template>
      </a-table>
      

      邏輯部分

      const keywords = ref("");
      // ↑ 用以儲存查詢關鍵詞的變量
      // ↓ 分頁對象
      const pagination = reactive({
        defaultPageSize: 8, // 默認每頁顯示多少個
        defaultCurrent: 1,
        total: 0,
        current: 1,
        onChange: (current: number, size: number) => {
          console.log("改變了頁數");
          console.log("current: ", current);
          console.log("size: ", size);
          pagination.current = current;
          getFruitsRequest(keywords.value, current, dataSource, pagination);
          // getFruitsRequest 函數在 api.js 這個文件里,下面會提到
        }
      })
      
      // 在掛載頁面時請求數據,此時 keywords 為空字符串
      onMounted(() => {
        getFruitsRequest(keywords.value, 1, dataSource, pagination);
      })
      
      // ↓ 表格列數據
      const columns = [
        {
          title: '水果名稱',
          dataIndex: 'fruitName',
          key: 'fruitName',
        },
        {
          title: '圖片',
          dataIndex: 'pic',
          key: 'pic',
        },
        {
          title: '價格 (元/公斤)',
          dataIndex: 'price',
          key: 'price',
        },
        {
          title: '庫存(公斤)',
          dataIndex: 'stock',
          key: 'stock',
        },
      ];
      
      /**
       * 點擊搜索按鈕的回調
       */
      function fnc_search() {
        // 輸入框 id 為 search
        // 這里通過 js 拿到 a-input 內的數據
        // 如果使用 v-model 方式的話會在輸入框內數據發生改變時就改變 keyword 的值
        // 導致在輸入框中有內容時,沒有點擊搜索按鈕而直接點擊翻頁按鈕也會觸發關鍵詞搜索
        if ((document.getElementById("search") as any).value === "") {
          // ↓ 如果值為空則將 keywords 置空
          keywords.value =  "";
        } else {
          // ↓ 前面加一個 '/' 為了拼接 api 接口
          // 例如:
          // http://www.xx00.com/fruits/1/5
          // ↑ 請求分頁,第一頁,請求五條數據
          // http://www.xx00.com/fruits/apple/2/3
          // ↑ 請求分頁,關鍵詞:apple,第二頁,請求三條數據
          keywords.value = '/' + (document.getElementById("search") as any).value;
        }
        getFruitsRequest(keywords.value, 1, dataSource, pagination);
        // ↓ 點擊搜索后,將當前頁數置為1
        pagination.current = 1;
      }
      
      // api.ts
      import axios from "axios";
      
      const fruitApi = axios.create({
          // 設置超出響應時間
          timeout: 5000
      })
      
      /**
       * 分頁查詢
       */
      export function getFruitsRequest(keywords = "", currentPage: number, dataSource: any, pagination: any) {
          fruitApi({
              method: 'get',
              url: 'api/fruits' + keywords + '/' + currentPage + '/8'
              // 默認請求 8 條數據
          })
              .then((resp) => {
                  console.log(resp.data);
                  // ↓ 分頁查詢需要 .records
                  dataSource.value = resp.data.records;
                  // ↑ 查詢完成后替換數據源
                  pagination.total = resp.data.total;
                  // ↑ 改變數據總數
              })
              .catch((e) => {
                  console.log("e: ", e);
              })
      }
      

      測試

      posted @ 2022-10-15 22:27  HuStoking  閱讀(1051)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产AV无码专区亚洲AV潘金链| 51妺嘿嘿午夜福利| 国产欧美日韩免费看AⅤ视频| 亚洲国产午夜精品福利| 人妻出轨av中文字幕| 玛沁县| 九九热在线精品视频99| 国产目拍亚洲精品二区| 欧美自拍另类欧美综合图片区| 亚洲精品成人网久久久久久| 制服丝袜国产精品| 亚洲国产日韩a在线播放| 一区二区三区无码高清视频| 精品国产午夜福利伦理片| 亚洲欧美偷国产日韩| 免费看女人与善牲交| 久久夜色精品国产亚洲a| 日本极品少妇videossexhd| 午夜大尺度福利视频一区| 乱老年女人伦免费视频| 久久一区二区中文字幕| 欧美成人精品三级网站| 欧美成人精品手机在线| 日韩 一区二区在线观看| 依依成人精品视频在线观看| 国产成人亚洲精品日韩激情| 国产第一页浮力影院入口| 国产白嫩护士在线播放| 99精品国产精品一区二区| 97色伦97色伦国产| 亚洲和欧洲一码二码三码| 文化| 国产性一交一乱一伦一色一情| 熟女精品视频一区二区三区| 日本成熟少妇喷浆视频| 欧美日韩一线| 衡阳县| 亚洲春色在线视频| 国产福利永久在线视频无毒不卡 | 日韩亚洲国产激情一区二区| 亚洲精品久久久久成人2007|