首页 > 其他分享 >el-table封装

el-table封装

时间:2022-11-21 00:12:16浏览次数:35  
标签:段落 el 封装 插槽 匿名 组件 table

el-table封装

要封装组件,首先要先简单了解slot插槽,插槽分为具名插槽和匿名插槽

  • 匿名插槽又称默认插槽,当slot没有指定name属性的时候就是一个匿名插槽,一个组件内只能有一个匿名插槽

例如:

子组件
<template>
	<div>
    	 
        <slot>这是一个匿名插槽</slot>
    </div>
</template>
父组件
<template>
	<div>
        <!-- 使用组件 -->
        <子组件>
         	<slot>我是匿名插槽<</slot>   
         </子组件>
    </div>
</template>
<script>
    import 子组件 from '路径'
    export default {
  components: {
    	子组件
  },

</script>
  • 具名插槽 在默认插槽的基础上添加指定插槽的名字(name=” “),父组件指定在子组件的那个插槽插入

    例如:

    子组件
    <template>
     <div>
       	<p>段落1</p>
           <slot name="btn">这是一个具名插槽</slot>
           <p>段落2</p>
       </div>
    </template>
    
    父组件
    <template>
    	<div>
            <!-- 使用组件 -->
            <子组件>
                <template v-slot:btn>我是匿名插槽</template> 
             </子组件>
        </div>
    </template>
    <script>
        import 子组件 from '路径'
        export default {
      components: {
        	子组件
      },
    
    </script>
    

    页面展示效果为:

    段落1

    我是具名插槽

    段落2

以下是封装的适用自己需要的table组件

子组件

        <el-table
            :data="tableData"
            style="width: 100%"
            border
            height='500'
            max-height='500'
            :header-cell-style=" {background:'#5987CF',color:'white',textAlign:'center',lineHeight:'30px',padding:'0'}"
            :cell-style="{'text-align':'center','line-height':'20px'}"
            >
            <!-- 单选多选框插槽 -->
            <slot name="chekAll"></slot> 
            <el-table-column
            v-for="item,index in tableTitle"
            :key="index"
            :prop="item.prop"
            :label="item.label"
            :width="item.width"
            :fixed="item.fixed"
            >
            <template slot-scope="scope">
            <!-- 特殊需求 -->
                <slot name="demand" :scope="scope" :item="item"></slot>
            </template>
            </el-table-column>
    </el-table>

父组件

 <Table :tableTitle="tableTitle" :tableData="tableData">
                <template #chekAll>
                    <el-table-column type="selection" width="55"></el-table-column>
                </template>
                <template v-slot:demand="{scope,item}">
                    <el-input v-if="item.prop == 'sy_jianshu'" v-model="scope.row.prop" />   
                    <el-button v-else-if="item.label == '操作'">删除</el-button>    
                    <span v-else>{{scope.row[item.prop]}}</span>         
                </template>
            </Table>

标签:段落,el,封装,插槽,匿名,组件,table
From: https://www.cnblogs.com/ermu007/p/16910095.html

相关文章

  • Python学习笔记:timedelta类相关函数
    一、介绍timedelta类表示时间差,可以直接实例化,也可以由两个datetime类型的数据作差得到。缘起于求两个时间差,并需要转换为特定的单位(天、小时、分钟等),遂产生此需求。......
  • el-table封装
    el-table封装子组件<el-table:data="tableData"style="width:100%"borderheight='500'max......
  • kernel module in UEFI secure boot --- insmod: ERROR: could not insert module lk
    #insmodlkm_hello.koinsmod:ERROR:couldnotinsertmodulelkm_hello.ko:Operationnotpermitted解决办法其实就是因为修改.ko文件是修改的linux内核文件,所以被bi......
  • EXCEL快捷键
         ......
  • xhell6解密脚本
    xhell6解密脚本importhashlibimportbase64string="ntauthority\systemS-1-5-18"#########sha256########sha256=hashlib.sha256()sha256.update(stri......
  • Linux 使用 iptables 禁止某些 IP 访问
    在Linux服务器被攻击的时候,有的时候会有几个主力IP。如果能拒绝掉这几个IP的攻击的话,会大大减轻服务器的压力,说不定服务器就能恢复正常了。在Linux下封停IP,有封杀网段和封......
  • Shell学习
    Shell学习参考资料:https://www.runoob.com/linux/linux-shell-variable.html变量变量的命名规则和其他语言基本一样your_name="qinjx"echo$your_nameecho${your_n......
  • 基于close channel广播机制来实现TimingWheel
    代码packagemainimport( "fmt" "sync" "time")typeTimingWheelstruct{ sync.Mutex intervaltime.Duration ticker*time.Ticker quitchanstruct{......
  • elk搭建
    elk搭建参考资料:https://www.cnblogs.com/adawoo/p/11665532.htmljdk安装https://www.cnblogs.com/cheesebar/p/9126171.htmlelk安装1.关闭防火墙和selinuxsy......
  • 2013-11-11 Oracle 课堂测试 练习题 例:BULK COLLECT及return table
    --1)查询“计算机”专业学生在“2007-12-15”至“2008-1-8”时间段内借书的--学生编号、学生名称、图书编号、图书名称、借出日期;selects.stuid,s.stuname,b.bid,b.ti......