npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

element-ui-table-template

v0.0.2

Published

基于element-ui封装的table主键

Readme

a table component based on element-ui

install

npm install element-ui-table-template

use

use

/*main.js中引入*/
import TableComponent from 'element-ui-table-template'
for (const condition in TableComponent) {
  Vue.component(TableComponent[condition].name, TableComponent[condition])
}

use in page

  • 1引入mixins.js
  • 2定义表头
  • 3...

mixins.js

export const TABLE_MIXINS = {
  data() {
    return {
      pageObj: { page: 1, limit: 10, total: 0 },
      queryParams: {},
      tableData: []
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      console.log('这是混入的初始化方法')
      this.getTableData()
    },
    // 查询按钮
    search() {
      this.pageObj.page = 1
      this.init()
    },
    // 分页长度改变
    handleSizeChange(val) {
      this.pageObj.limit = val
      this.init()
    },
    // 分页页码改变
    handleCurrentChange(val) {
      this.pageObj.page = val
      this.init()
    },
    getQueryParams() {
      const queryParams = { ...this.queryParams, ...this.pageObj }
      delete queryParams['total']
      return queryParams
    }
  }
}

page example

<!--suppress ALL -->
<template>
  <!--table模板-->
  <table-layout :span-method="spanMethod" :page-obj="pageObj" :headers="headers" :table-data="tableData" @sizeChange="handleSizeChange" @currentChange="handleCurrentChange" @handleRowClick="handleRowClick" @handleCellClick="handleCellClick" @selectionChange="handleSelectionChange">
    <template slot="top-left">
      左边插槽
    </template>
    <template slot="top-right">
      右边插槽
    </template>
    <!---->
    <template slot="expand" slot-scope="{scope}">
      <el-form label-position="left" inline class="demo-table-expand">
        <el-form-item label="名称">
          {{ scope.row.name }}
        </el-form-item>
      </el-form>
    </template>
    <!--姓名电话-->
    <template slot="name-phone" slot-scope="{scope}">
      <div> <i class="el-icon-time"/>{{ scope.row.name }}</div>
      <div> <i class="el-icon-time"/>{{ scope.row.phone }}</div>
    </template>
    <!--头像-->
    <template slot="avatar" slot-scope="{scope}">
      <img :src="scope.row.avatar" alt="头像">
    </template>
    <!--操作-->
    <template slot="operator" slot-scope="{scope}">
      <el-button @click="handleView(scope.row)">查看</el-button>
      <el-button @click="handleDel(scope.row)">删除</el-button>
    </template>
  </table-layout>
</template>

<script>
import { TABLE_MIXINS } from './../../mixins/table_mixins'
export default {
  name: 'Table2',
  mixins: [TABLE_MIXINS],
  data() {
    return {
      headers: [
        { type: 'selection' },
        { type: 'expand', slot: 'expand' },
        { type: 'index', fixed: true },
        { prop: 'id', label: 'id' },
        { prop: 'name', label: '姓名', slot: 'name-phone' },
        { prop: 'loginName', label: '登录名' },
        { prop: 'nickName', label: '昵称' },
        { prop: 'avatar', label: '头像', width: 300, slot: 'avatar' },
        { prop: 'age', label: '年龄' },
        { prop: 'status', label: '状态' },
        { prop: 'acorpName', label: '公司名称' },
        { prop: 'departmentName', label: '部门名称' },
        { prop: 'description', label: '描述' },
        { prop: 'time',
          label: '时间',
          children: [
            { prop: 'createTime',
              label: '创建时间',
              children: [
                { prop: 'createTime', label: '创建时间' },
                { prop: 'updateTime', label: '更新时间' }
              ] },
            { prop: 'updateTime', label: '更新时间' }
          ] },
        { label: '操作', slot: 'operator', fixed: 'right', width: 180 }
      ],
      queryParams: {
        keyword: ''
      }
    }
  },
  created() {
    this.queryParams.keyword = 'keyword'
  },
  methods: {
    init() {
      console.log('init方法做一些其它事情')
      this.getTableData()
    },
    getQueryParams() {
      console.log('重写getQueryParams')
      const queryParams = { ...this.queryParams, ...this.pageObj }
      delete queryParams['total']
      return queryParams
    },
    spanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 2) {
        if (rowIndex % 2 === 0) {
          return {
            rowspan: 2,
            colspan: 1
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    },
    handleView(obj) {
      console.log('查看对象:%o', obj)
    },
    handleDel(obj) {
      console.log('删除对象:%o', obj)
    },
    getTableData() {
      const page = this.pageObj.page
      const limit = this.pageObj.limit
      this.pageObj.total = 100
      this.tableData = []
      for (let i = 0; i < limit; i++) {
        this.tableData.push({ id: page * limit + i, name: '测试' + page * limit + i })
      }
    },
    handleSelectionChange(val) {
      console.log(val)
    },
    handleRowClick(row, event, column) {
      console.log('点击行对象:%o', row)
    },
    handleCellClick(row, column, cell, event) {
      console.log('点击单元格对象:%o', cell)
    }
  }
}
</script>

文档

参考element-ui 表格主键 Table Attributes大致相同, Table-column Attributes需转化为header对象