JSFiddle - React, Tailwind, and code Playground

by pcloth

HTML

<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/element-ui@2.4.5/lib/index.js"></script>
<script src="//unpkg.com/vue-easy-print@0.0.6/dist/vue-easy-print.js"></script>
<div id="app">
  <button @click="print">
    打印下面的区域
  </button>
  <vue-easy-print table-show ref="easyPrint">
    <template slot-scope="func">
      <p>
      你要打印的内容放到slot区域,当然也可以直接插入某个你自己写好的组件,当前渲染出来的内容就是要打印的内容,vue-easy-print会将这些内容,连同当前页面的css一起复制出来制作打印页面。
      </p>
      <span>{{money}} <br> {{func.getChineseNumber(money)}}</span>
      
      <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="date" label="日期" width="180">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="180">
      </el-table-column>
      <el-table-column prop="address" label="地址">
      </el-table-column>
    </el-table>
    </template>
  </vue-easy-print>
</div>

CSS

@import url("//unpkg.com/element-ui@2.4.5/lib/theme-chalk/index.css");
@import url("//unpkg.com/vue-easy-print@0.0.6/dist/vue-easy-print.css");

JavaScript

VueEasyPrint.install(Vue)

new Vue({
    el: "#app",
    data() {
          return {
             money: 544641.54,
             tableData: [{
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
          }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄'
          }, {
            date: '2016-05-01',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1519 弄'
          }, {
            date: '2016-05-03',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1516 弄'
          }]
          };
      },
    methods:{
    		print(){
        		this.$refs.easyPrint.print()
        }
    }
   
})