(Vue)调用接口引用elementUI表格显示

1.下载elementUI

npm i element-ui -S

2.在main.js中使用

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

3.创建table

<el-table
          :data="tableData"
          :height="tableHeight"
          :header-cell-style="{color:'#fff',background:'rgba(35,205,253,0.1)'}"
          :cell-style="{color:'#fff'}"
        >
          <el-table-column prop="id" label="编号" min-width="5%"></el-table-column>
          <el-table-column prop="sname" label="服务名称" min-width="15%"></el-table-column>
          <el-table-column prop="surl" label="接口地址" min-width="12%"></el-table-column>
          <el-table-column prop="sdescription" label="功能描述" min-width="10%"></el-table-column>
          <el-table-column prop="sinput" label="输入描述" min-width="12%" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="soutput" label="输出描述" min-width="12%"></el-table-column>
          <el-table-column prop="sinstance" label="调用示例" min-width="10%" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="srequest" label="请求方式" min-width="5%"></el-table-column>
          <el-table-column prop="senable" label="状态" min-width="5%"></el-table-column>
</el-table>

其中<el-table-column></el-table-column>是每一列

prop:对应接口中的名称
label:表头的名称
min-width:按照百分比设定该列宽度(设置width可能没有效)

4.调用接口

  data () {
      return {
      	tableData: [],
    }
  },
getAjaxData() {
      this.tableData = [];
      var that = this;
      $.ajax({
        type: "get", 
        async: true,
        url:"*************************",//接口地址
        data: "",
        dataType: "json", 
        crossDomain: true,
        success: function(res){
          console.log(res);
          $.each(res, function (i, val) {
            that.tableData.push(res[i]);
          });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          console.log("请求对象XMLHttpRequest: " + XMLHttpRequest.status);
          console.log("XMLHttpRequest.readyState: " + XMLHttpRequest.readyState);
          console.log("错误类型textStatus: " + textStatus);
          console.log("异常对象errorThrown: " + errorThrown);
        }
      });
    },  //获取接口数据
created () {
    this.getAjaxData();
  }

接口格式:
在这里插入图片描述
———————————————————————————————————————

(1)表格中内容太长(显示tooltip)

show-overflow-tooltip=“true”

<el-table-column 
	prop="sdescription" 
	label="功能描述" 
	min-width="10%" 
	:show-overflow-tooltip="true">
</el-table-column>

在这里插入图片描述 在这里插入图片描述

(2)tooltip换行
<el-table-column prop="sinput" label="输入描述" min-width="12%">
     <template slot-scope="scope">
       <el-tooltip
         :disabled="scope.row.sinput === '' "
         placement="top"
         effect="dark">
         <div slot="content" style="width: auto;overflow-x: auto;"
              v-for="item in ((scope.row.sinput || '').split(';'))">{{ item }}</div>
         <ul  class="name-wrapper" style="cursor: pointer;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
           <li v-for="item in ((scope.row.sinput || '').split(','))" style="text-align: left">{{ item }}</li>
         </ul>
       </el-tooltip>
     </template>
</el-table-column>

在这里插入图片描述

(3)tooltip按原格式显示json数据
<el-table-column prop="sinstance" label="调用示例" min-width="12%">
   <template slot-scope="scope">
     <el-tooltip
       :disabled="scope.row.sinstance === '' "
       placement="top"
       effect="dark">
         <div slot="content" style="width: auto;height:500px;overflow-x: auto;"><pre><code>{{ scope.row.sinstance }}</code></pre></div>
         <ul  class="name-wrapper" style="cursor: pointer;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
           <li v-for="item in ((scope.row.sinstance || '').split(','))" style="text-align: left">{{ item }}</li>
         </ul>
     </el-tooltip>
   </template>
</el-table-column>

在这里插入图片描述

(4)根据接口数据显示不同内容
<el-table-column prop="senable" label="状态" min-width="5%">
   <template slot-scope="scope">
     {{ enable[scope.row.senable] }}
   </template>
</el-table-column>
data () {
    return {
      enable: {
        F: '1',
        T: '2',
      }
    }

在这里插入图片描述 在这里插入图片描述

(5)根据接口数据返回不同图片
<el-table-column prop="senable" label="状态" min-width="5%">
   <template slot-scope="scope">
     <el-image
       class="table-td-thumb"
       :src="require('../../static/ps/'+scope.row.senable+'.png')"
     ></el-image>
   </template>
</el-table-column>

如果需要点击图片放大显示,添加下面这一行

:preview-src-list="[require('../../static/ps/'+scope.row.senable+'.png')]"

在这里插入图片描述

(6)滑块滚动条样式
.treeScrollbar::-webkit-scrollbar-thumb {
    background-color: #409EFF!important;
    background-clip: padding-box;
    min-height: 28px;
    border-radius: 8px;
  }

  .treeScrollbar::-webkit-scrollbar-thumb:hover {
    background-color: #409EFF;
  }

  *::-webkit-scrollbar {width:10px; height:10px; background-color:transparent!important;} /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  *::-webkit-scrollbar-track {width:10px; height:10px;background-color:#f0f6ff;  } /*定义滚动条轨道 内阴影+圆角*/
  *::-webkit-scrollbar-thumb {background-color:#409EFF;} /*定义滑块 内阴影+圆角*/
  .scrollbarHide::-webkit-scrollbar{display: none}
  .scrollbarShow::-webkit-scrollbar{display: block}

在这里插入图片描述

(7)表格每一行高
<el-table :row-style="rowStyle"></el-table>        
methods: {
    rowStyle(){
      return{
        height:"100px"
      }
    },
  },

———————————————————————————————————————

代码:
<template>
  <el-container class="container" direction="vertical">
      <el-main class="user_skills" >
        <div style="height: 70px"></div>
          <el-table
            :data="tableData"
            :height="tableHeight"
            :header-cell-style="{color:'#fff',background:'rgba(35,205,253,0.1)'}"
            :cell-style="{color:'#fff'}"
            :row-style="rowStyle"
          >
            <el-table-column prop="id" label="编号" min-width="4%"></el-table-column>
            <el-table-column prop="sname" label="服务名称" min-width="12%"></el-table-column>
            <el-table-column prop="surl" label="接口地址" min-width="12%"></el-table-column>
            <el-table-column prop="sdescription" label="功能描述" min-width="10%" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="sinput" label="输入描述" min-width="12%">
              <template slot-scope="scope">
                <el-tooltip
                  :disabled="scope.row.sinput === '' "
                  placement="top"
                  effect="dark">
                  <div slot="content" style="width: auto;overflow-x: auto;"
                       v-for="item in ((scope.row.sinput || '').split(';'))">{{ item }}</div>
                  <ul  class="name-wrapper" style="cursor: pointer;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
                    <li v-for="item in ((scope.row.sinput || '').split(','))" style="text-align: left">{{ item }}</li>
                  </ul>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column prop="soutput" label="输出描述" min-width="12%" >
              <template slot-scope="scope">
                <el-tooltip
                  :disabled="scope.row.soutput === '' "
                  placement="top"
                  effect="dark">
                  <div slot="content" style="width: auto;overflow-x: auto;"
                       v-for="item in ((scope.row.soutput || '').split(';'))">{{ item }}</div>
                  <ul  class="name-wrapper" style="cursor: pointer;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
                    <li v-for="item in ((scope.row.soutput || '').split(','))" style="text-align: left">{{ item }}</li>
                  </ul>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column prop="sinstance" label="调用示例" min-width="12%">
              <template slot-scope="scope">
                <el-tooltip
                  :disabled="scope.row.sinstance === '' "
                  placement="top"
                  effect="dark">
                    <div slot="content" style="width: auto;height:500px;overflow-x: auto;"><pre><code>{{ scope.row.sinstance }}</code></pre></div>
                    <ul  class="name-wrapper" style="cursor: pointer;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
                      <li v-for="item in ((scope.row.sinstance || '').split(','))" style="text-align: left">{{ item }}</li>
                    </ul>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column prop="srequest" label="请求方式" min-width="8%"></el-table-column>
            <el-table-column prop="senable" label="状态" min-width="5%">
              <template slot-scope="scope">
                <el-image
                  class="table-td-thumb"
                  :src="require('../../static/ps/'+scope.row.senable+'.png')"
                  :preview-src-list="[require('../../static/ps/'+scope.row.senable+'.png')]"
                ></el-image>
              </template>
            </el-table-column>
          </el-table>
        </el-main>
    </el-container>
</template>
<script>
import $ from 'jquery';
export default {
  name: 'Table',
  data () {
    return {
      tableHeight: window.innerHeight - 180,

      tableData: [],

    }
  },
  components: {
  },

  methods: {
    getAjaxData() {
      this.tableData = [];
      var that = this;
      $.ajax({
        type: "get", //get post
        async: true,
        url:"*********************",
        data: "",
        dataType: "json",
        crossDomain: true,
        success: function(res){

          console.log(res);
          $.each(res, function (i, val) {
            that.tableData.push(res[i]);
          });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
          console.log("请求对象XMLHttpRequest: " + XMLHttpRequest.status);
          console.log("XMLHttpRequest.readyState: " + XMLHttpRequest.readyState);
          console.log("错误类型textStatus: " + textStatus);
          console.log("异常对象errorThrown: " + errorThrown);
        }
      });
    },  //获取接口数据
    rowStyle(){
      return{
        height:"100px"
      }
    },
  },
  created () {
    this.getAjaxData();
  }
}
</script>
<style scoped>
  .container{
    background-repeat: no-repeat;
    background-position: center center;
    background-size:100% 100%;
    position:relative;
  }
  .user_skills{
    position: relative;
  }
  /*.user_skills /deep/ .el-table--fit{*/
    /*padding: 0px;*/
  /*}*/
  .user_skills /deep/  .el-table, .el-table__expanded-cell, .el-table-column {
    background-color: transparent!important;
    text-align: center!important;
  }
  .el-table--striped .el-table__body tr.el-table__row--striped.current-row td, .el-table__body tr.current-row>td {
    color: #fff;
    background-color: #a2a4a7!important;
  }
  .el-table__body tr.current-row>td {
    background-color: transparent!important;
  }



</style>

<style>
  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 30px;
    line-height: 30px;
  }
  .el-table--enable-row-hover .el-table__body tr:hover>td{
    background-color:transparent;
    color:#23CDFD!important;
  }
  .el-table--border::after, .el-table--group::after, .el-table::before{
    background-color: transparent!important;
  }
  .el-menu-item:hover{
    outline: 0 !important;
    color: #409EFF !important;
    background-color: transparent!important;
  }
  .el-menu-item.is-active {
    color: #fff !important;
    background: #409EFF !important;
  }
  .el-table__row>td{
    border: #409EFF!important;
  }
  .treeScrollbar::-webkit-scrollbar-track-piece {
    background-color: #fff!important;
  }

  .treeScrollbar::-webkit-scrollbar {
    width: 100px;
    height: 10px;
  }
  .el-scrollbar__bar {
    opacity: 1;
  }

  .treeScrollbar::-webkit-scrollbar-thumb {
    background-color: #409EFF!important;
    background-clip: padding-box;
    min-height: 28px;
    border-radius: 8px;
  }

  .treeScrollbar::-webkit-scrollbar-thumb:hover {
    background-color: #409EFF;
  }

  *::-webkit-scrollbar {width:10px; height:10px; background-color:transparent!important;} /*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
  *::-webkit-scrollbar-track {width:10px; height:10px;background-color:#f0f6ff;  } /*定义滚动条轨道 内阴影+圆角*/
  *::-webkit-scrollbar-thumb {background-color:#409EFF;} /*定义滑块 内阴影+圆角*/
  .scrollbarHide::-webkit-scrollbar{display: none}
  .scrollbarShow::-webkit-scrollbar{display: block}


</style>

在这里插入图片描述
样式上如果不太一致因为还改了elementUI里面index.css文件,忘了改了哪些了把最后的文件发出来吧…


链接:https://pan.baidu.com/s/1AEx8pTG9SU78366P4czAdw
提取码:1234
复制这段内容后打开百度网盘手机App,操作更方便哦


路径是这个

\node_modules\element-ui\lib\theme-chalk\index.css

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值