点击打印后可以打印表格和表单的数据,同时样式也在
<template>
<div>
<div id="printFrom" ref="printDom">
<el-table :data="tableData" style="width: 100%" border>
<el-table-column prop="date" label="日期" align="center"></el-table-column>
<el-table-column prop="name" label="姓名" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
</el-table>
<el-form>
<el-row>
<el-col :span="12">
<el-form ref="form" :model="form" label-width="100px">
<el-form-item label="姓名">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="身份证">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="性别">
<el-input v-model="form.name"></el-input>
</el-form-item>
</el-form>
</el-col>
<el-col :span="12">
<el-table :data="tableData" style="width: 100%" border>
<el-table-column prop="date" label="日期" align="center"></el-table-column>
<el-table-column prop="name" label="姓名" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
</el-table>
</el-col>
</el-row>
</el-form>
</div>
<button @click="print">打印</button>
</div>
</template>
<style lang="scss" scoped>
</style>
<script>
export default {
data() {
return {
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 弄',
},
],
form: {
name: '',
},
}
},
methods: {
//打印
print() {},
},
}
</script>
改用vue-print-nb
解决了整个问题
<template>
<div>
<div id="printFrom" ref="printDom">
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="活动名称">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="活动区域">
<el-select v-model="form.region" placeholder="请选择活动区域">
<el-option label="区域一" value="shanghai"></el-option>
<el-option label="区域二" value="beijing"></el-option>
</el-select>
</el-form-item>
<el-form-item label="活动时间">
<el-col :span="11">
<el-date-picker
type="date"
placeholder="选择日期"
v-model="form.date1"
style="width: 100%;"
></el-date-picker>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker>
</el-col>
</el-form-item>
<el-form-item label="即时配送">
<el-switch v-model="form.delivery"></el-switch>
</el-form-item>
<el-form-item label="活动性质">
<el-checkbox-group v-model="form.type">
<el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
<el-checkbox label="地推活动" name="type"></el-checkbox>
<el-checkbox label="线下主题活动" name="type"></el-checkbox>
<el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
</el-checkbox-group>
</el-form-item>
<el-form-item label="特殊资源">
<el-radio-group v-model="form.resource">
<el-radio label="线上品牌商赞助"></el-radio>
<el-radio label="线下场地免费"></el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="活动形式">
<el-input type="textarea" v-model="form.desc"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" class="no-print">立即创建</el-button>
<el-button class="no-print">取消</el-button>
</el-form-item>
</el-form>
<el-table :data="tableData" style="width: 100%" border>
<el-table-column prop="date" label="日期" align="center"></el-table-column>
<el-table-column prop="name" label="姓名" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
<el-table-column prop="address" label="地址" align="center"></el-table-column>
</el-table>
<el-descriptions title="用户信息">
<el-descriptions-item label="用户名">kooriookami</el-descriptions-item>
<el-descriptions-item label="手机号">18100000000</el-descriptions-item>
<el-descriptions-item label="居住地">苏州市</el-descriptions-item>
<el-descriptions-item label="备注">
<el-tag size="small">学校</el-tag>
</el-descriptions-item>
<el-descriptions-item label="联系地址">江苏省苏州市吴中区吴中大道 1188 号</el-descriptions-item>
</el-descriptions>
</div>
<button v-print="printObj">打印</button>
</div>
</template>
<style lang="scss" scoped>
@page {
size: auto;
margin: 3mm;
}
@media print {
/deep/ table {
table-layout: auto !important;
}
/deep/ .el-table__header-wrapper .el-table__header {
width: 100% !important;
}
/deep/ .el-table__body-wrapper .el-table__body {
width: 100% !important;
}
/deep/ #print table {
table-layout: fixed !important;
}
/deep/.el-table__fixed {
display: none;
}
/deep/.el-table .el-table__cell.is-hidden > * {
visibility: visible;
font-size: 12px;
}
.no-print {
display: none;
}
}
</style>
<script>
import print from 'vue-print-nb'
export default {
directives: {
print,
},
data() {
return {
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 弄',
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
},
],
form: {
name: '',
region: '',
date1: '',
date2: '',
delivery: false,
type: [],
resource: '',
desc: '',
},
printObj: {
id: 'printFrom',
popTitle: '打印', // 打印配置页上方标题
extraHead: '', //最上方的头部文字,附加在head标签上的额外标签,使用逗号分隔
preview: '', // 是否启动预览模式,默认是false(开启预览模式,可以先预览后打印)
previewTitle: '', // 打印预览的标题(开启预览模式后出现),
previewPrintBtnLabel: '', // 打印预览的标题的下方按钮文本,点击可进入打印(开启预览模式后出现)
zIndex: '', // 预览的窗口的z-index,默认是 20002(此值要高一些,这涉及到预览模式是否显示在最上面)
previewBeforeOpenCallback: () => {}, //预览窗口打开之前的callback(开启预览模式调用)
previewOpenCallback: () => {}, // 预览窗口打开之后的callback(开启预览模式调用)
beforeOpenCallback: () => {}, // 开启打印前的回调事件
openCallback: () => {}, // 调用打印之后的回调事件
closeCallback: () => {}, //关闭打印的回调事件(无法确定点击的是确认还是取消)
url: '',
standard: '',
extraCss: '',
},
}
},
methods: {},
}
</script>
用print.js
先安装:npm install print-js
然后使用:
print() {
printJS({
printable: this.$refs.printDom.innerHTML,
type: 'html',
header: '打印预览', // 自定义打印预览的标题
css: [
process.env.BASE_URL + 'node_modules/element-ui/lib/theme-chalk/index.css',
process.env.BASE_URL + 'path/to/your/custom/styles.css'
],
scanStyles: false
})
}
或者用Vue HTML to Paper其实你的功能需求就是弄成pdf
https://github.com/mycurelabs/vue-html-to-paper
import Vue from 'vue';
import VueHtmlToPaper from 'vue-html-to-paper';
const options = {
name: '_blank',
specs: ['fullscreen=yes', 'titlebar=yes', 'scrollbars=yes'],
styles: [
'https://unpkg.com/element-ui/lib/theme-chalk/index.css',
// 在此处添加其他样式表路径
],
};
Vue.use(VueHtmlToPaper, options);
组件里:
methods: {
print() {
this.$htmlToPaper(this.$refs.printDom);
},
},
详细可以看看官网和相关的文章
ResizeObserver loop limit exceeded 为什么本地会报这个错,正式环境上没有?
第一层是父节点,点击下面的子节点,子节点已经被选中了,但是没有选中打勾的效果 全选所有、选择父级都可以,但是只要父级下面有多个子节点,选择其中一个子节点的时候就不行,如果只有一个子节点也是可以的 代码是参考这个写的 作者:阿wei程序媛 https://blog.csdn.net/m0_58565372/article/details/130766588
请问这样的数据在el-table里如何渲染出来,activityList也要渲染 id activityList 1 test1(2),test2(3) 这样的数据应该如何去渲染 还是处理一下rows里面的activityList这个数据?
共同点是两者都可以下拉
以下是elmentui2的源码: 我看明明是挂载到tbody下的,为什么悬浮提示的时候显示的是在body节点下?而且每次都销毁之前的创建一个新的,这种做法是怎么做到的?
现在需要修改el-table-column slot="header" 中的 el-checkbox控制状态,选择表头的el-checkbox其他行checkbox都选中/取消这个已实现,但是当取消选择所有selected时,表头selectAll取消/选中失败,代码如下。js能打印出selectAll状态已发生改变,那么就是视图没有更新。思考了很久,没有找到合适的解决办法,请大佬们看看问题出现在