Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/[email protected]/lib/index.js"></script>
<div id="app">
<template>
  <div>
    <div>
      <label>请选择表格需要展示的列:</label>
      <el-checkbox-group v-model="checkedTableColumns">
        <el-checkbox
          v-for="column in tableColumns"
          :key="column.prop"
          :label="column.prop"
          >{{ column.label }}</el-checkbox
        >
      </el-checkbox-group>
    </div>
    <el-table :data="tableData" border>
      <el-table-column
        v-for="column in bindTableColumns"
        :key="column.prop"
        :prop="column.prop"
        :label="column.label"
      ></el-table-column>
    </el-table>
  </div>
</template>
</div>
              
            
!

CSS

              
                @import url("//unpkg.com/[email protected]/lib/theme-chalk/index.css");

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

/* .el-table {
  border: 1px solid red;
} */

              
            
!

JS

              
                  var Main = {
    data() {
      return {
        tableData: [
          {
            date: "2016-05-02",
            name: "王小虎",
            address: "上海市普陀区金沙江路 1518 弄",
          },
          {
            date: "2016-05-04",
            name: "王小虎",
            address: "上海市普陀区金沙江路 1517 弄",
          },
          {
            date: "2016-05-01",
            name: "王小虎",
            address: "上海市普陀区金沙江路 1519 弄",
          }
        ],
        tableColumns: [
          {
            prop: "date",
            label: "日期",
            show: true,
          },
          {
            prop: "name",
            label: "姓名",
            show: true,
          },
          {
            prop: "address",
            label: "地址",
            show: true,
          },
        ],
      };
    },
    computed: {
      bindTableColumns() {
        return this.tableColumns.filter((column) => column.show);
      },
      /* 这里使用了getter和setter,这样写的好处不用自己手动监听复选框的选中事件 */
      checkedTableColumns: {
        get() {
          // 返回选中的列名
					return this.bindTableColumns.map(column => column.prop);
        },
        set(checked) {
          // 设置表格列的显示与隐藏
          this.tableColumns.forEach((column, index) => {
            // 如果选中,则设置列显示
            if(checked.includes(column.prop)) {
              column.show = true;
            } else {
              // 如果未选中,则设置列隐藏
              column.show = false;
            }
          })
        }
      }
    }
  };
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')
              
            
!
999px

Console