<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          前端開發(fā) =》Vue刷怪小妙招

          共 8327字,需瀏覽 17分鐘

           ·

          2021-08-09 10:47

          數(shù)據(jù)字典

          • 效果如下

          添加路由

          • src/router/index.js

            {
              path: '/cmn',
              component: Layout,
              redirect: '/cmn/list',
              name: '數(shù)據(jù)管理',
              alwaysShow: true, //顯示有層次
              meta: { title: '數(shù)據(jù)管理', icon: 'example' },
              children: [
                {
                  path: 'list',
                  name: '數(shù)據(jù)字典',
                  component: () => import('@/views/dict/list'),
                  meta: { title: '數(shù)據(jù)字典', icon: 'table' }
                }
              ]
            }

          定義api

          • src/api/dict.js
          import request from '@/utils/request'
          export default{
            dictList(id){
              return request({
                url: `/admin/cmn/dict/findChildData/${id}`,
                method: 'get'
              })
            },
          }

          調(diào)用方法

          <script>
          import dict from "@/api/dict";

          export default {
            data() {
              return {
                list: [],
                dialogImportVisible:false  //設(shè)置彈框是否彈出
              };
            },
            created() {
              this.getDictList(1);
            },
            methods: {
              //數(shù)據(jù)字典列表
              getDictList(id) {
                dict
                  .dictList(id)
                  .then((response) => {
                    this.list = response.data;
                  })
                  .catch((error) => {});
              },
              //下拉加載數(shù)據(jù)
              getChildrens(tree, treeNode, resolve) {
                dict.dictList(tree.id).then((response) => {
                  resolve(response.data);
                });
              },
            },
          };
          </script>

          頁面渲染

          <el-table
                :data="list"
                style="width: 100%"
                row-key="id"
                border
                lazy
                :load="getChildrens"
                :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
              >
                <el-table-column label="名稱" width="230" align="left">
                  <template slot-scope="scope">
                    <span>{{ scope.row.name }}</span>
                  </template>
                </el-table-column>

                <el-table-column label="編碼" width="220">
                  <template slot-scope="{ row }">
                    {{ row.dictCode }}
                  </template>
                </el-table-column>
                <el-table-column label="值" width="230" align="left">
                  <template slot-scope="scope">
                    <span>{{ scope.row.value }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="創(chuàng)建時間" align="center">
                  <template slot-scope="scope">
                    <span>{{ scope.row.createTime }}</span>
                  </template>
                </el-table-column>
              </el-table>

          導出

          • 組件
              <div class="el-toolbar">
                <div class="el-toolbar-body" style="justify-content: flex-start">
                  <el-button type="text" @click="exportData"
                    ><i class="fa fa-plus" /> 導出</el-button
                  >
                  <el-button type="text" @click="importData"
                    ><i class="fa fa-plus" /> 導入</el-button
                  >
                </div>
              </div>
          • 組件接口
           //導出數(shù)據(jù)
              exportData() {
                window.location.href = "http://localhost:8202/admin/cmn/dict/exportData";
              },

          導入

          • 彈框
            • 效果圖
            • 組件
             <el-dialog title="導入" :visible.sync="dialogImportVisible" width="480px">
                <el-form label-position="right" label-width="170px">
                  <el-form-item label="文件">
                    <el-upload
                      :multiple="false"
                      :on-success="onUploadSuccess"
                      :action="'http://localhost:8202/admin/cmn/dict/importData'"
                      class="upload-demo"
                    >
                      <el-button size="small" type="primary">點擊上傳</el-button>
                      <div slot="tip" class="el-upload__tip">
                        只能上傳xls文件,且不超過500kb
                      </div>
                    </el-upload>
                  </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button @click="dialogImportVisible = false"> 取消 </el-button>
                </div>
              </el-dialog>
          • 組件接口
              //數(shù)據(jù)導入
              importData() {
                  this.dialogImportVisible = true;  //設(shè)置彈框是否彈出
              },
              //上傳成功調(diào)用的方法
              onUploadSuccess(){
                  this.dialogImportVisible = false;  //設(shè)置彈框是否彈出
                  this.getDictList(1);
              },

          到這里導入導出基本已經(jīng)完善好了,包括列表的編輯、刪除以及添加操作,模糊查詢


          瀏覽 52
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  99在线精品视频观看 | 色色色免费AV | 日韩乱轮视频 | 亚洲 A V中文字幕 | 肏屄在线视频 |