Coder Social home page Coder Social logo

vueplugs_printjs's Introduction

vuePlugs_printjs

vue打印插件 使用方法

import Print from '@/plugs/print'
Vue.use(Print) // 注册
<template>
<section ref="print">
	打印内容
	<div class="no-print">不要打印我</div>
</section>
</template>
this.$print(this.$refs.print) // 使用

注意事项 需使用ref获取dom节点,若直接通过id或class获取则webpack打包部署后打印内容为空 指定不打印区域 方法一. 添加no-print样式类

<div class="no-print">不要打印我</div>

方法二. 自定义类名

<div class="do-not-print-me-xxx">不要打印我</div>
this.$print(this.$refs.print,{'no-print':'.do-not-print-me-xxx'}) // 使用

vueplugs_printjs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vueplugs_printjs's Issues

无法打印组件里的内容

vue 项目中引入的有chart.js组件,打印的时候不显示。
打印的时候13212显示 但是下方的line-chart组件内容不显示。

13212

浏览器兼容,ie11,ie10无法读取样式

避免踩坑总结:1.调用打印的方法:this.$print(this.$refs.print)
2.js文件有处地方不符合严格模式,ie会报错
代码:iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
修改为:iframe.setAttribute('style','position:absolute;width:0;height:0;top:-10px;left:-10px;')
开发环境中浏览器:谷歌,火狐,edge都正常,ie10,ie11无法读取css样式

更改writeIframe方法:

更改writeIframe方法:
writeIframe: function (content) {
var w, doc, iframe = document.createElement('iframe'),
f = document.body.appendChild(iframe);
var style = document.createElement("style");
style.type = "text/css";
try {
style.appendChild(document.createTextNode("@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"));
} catch (ex) {
style.styleSheet.cssText = "@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"; //针对IE
}
iframe.id = "myIframe";
//iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
w = f.contentWindow || f.contentDocument;
doc = f.contentDocument || f.contentWindow.document;
var head = doc.getElementsByTagName("head")[0];
// head.appendChild(style);
doc.open();
doc.write(content);
doc.close();
var _this = this
iframe.onload = function () {
_this.toPrint(w);
setTimeout(function () {
document.body.removeChild(iframe)
}, 100)
}
},

Originally posted by @quqingfei in #14 (comment)

css 兼容打印空白

对文字设置换行属性
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;

后打印结果 空白

isDOM方法不存在

Error in event handler for "click": "TypeError: this.isDOM is not a function"

found in

--->

at src/pages/form/engineeringEvent/read.vue
at src/App.vue

更改writeIframe方法:

更改writeIframe方法:
writeIframe: function (content) {
var w, doc, iframe = document.createElement('iframe'),
f = document.body.appendChild(iframe);
var style = document.createElement("style");
style.type = "text/css";
try {
style.appendChild(document.createTextNode("@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"));
} catch (ex) {
style.styleSheet.cssText = "@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"; //针对IE
}
iframe.id = "myIframe";
//iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
w = f.contentWindow || f.contentDocument;
doc = f.contentDocument || f.contentWindow.document;
var head = doc.getElementsByTagName("head")[0];
// head.appendChild(style);
doc.open();
doc.write(content);
doc.close();
var _this = this
iframe.onload = function () {
_this.toPrint(w);
setTimeout(function () {
document.body.removeChild(iframe)
}, 100)
}
},

Originally posted by @quqingfei in #14 (comment)

日期无法打印

input 标签日期插件 输入日期都打印是年/月/日 不是选择的日期

更改writeIframe方法:

更改writeIframe方法:
writeIframe: function (content) {
var w, doc, iframe = document.createElement('iframe'),
f = document.body.appendChild(iframe);
var style = document.createElement("style");
style.type = "text/css";
try {
style.appendChild(document.createTextNode("@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"));
} catch (ex) {
style.styleSheet.cssText = "@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"; //针对IE
}
iframe.id = "myIframe";
//iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
w = f.contentWindow || f.contentDocument;
doc = f.contentDocument || f.contentWindow.document;
var head = doc.getElementsByTagName("head")[0];
// head.appendChild(style);
doc.open();
doc.write(content);
doc.close();
var _this = this
iframe.onload = function () {
_this.toPrint(w);
setTimeout(function () {
document.body.removeChild(iframe)
}, 100)
}
},

Originally posted by @quqingfei in #14 (comment)

更改writeIframe方法:

更改writeIframe方法:
writeIframe: function (content) {
var w, doc, iframe = document.createElement('iframe'),
f = document.body.appendChild(iframe);
var style = document.createElement("style");
style.type = "text/css";
try {
style.appendChild(document.createTextNode("@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"));
} catch (ex) {
style.styleSheet.cssText = "@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"; //针对IE
}
iframe.id = "myIframe";
//iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
w = f.contentWindow || f.contentDocument;
doc = f.contentDocument || f.contentWindow.document;
var head = doc.getElementsByTagName("head")[0];
// head.appendChild(style);
doc.open();
doc.write(content);
doc.close();
var _this = this
iframe.onload = function () {
_this.toPrint(w);
setTimeout(function () {
document.body.removeChild(iframe)
}, 100)
}
},

Originally posted by @quqingfei in #14 (comment)

This dependency was not found

  • @/src/utils/print.js in ./node_modules/babel-loader/lib!./node_modules/vue-loa
    der/lib/selector.js?type=script&index=0!./src/views/deliver/index.vue

样式丢失:非根css选择器的情况下会丢失

问题

一次写scss多层嵌套后发现样式丢失,经过观察,发现dom样式不同。有多层选择器时打印样式丢失,唯一选择器时正常。

情况描述

打印节点

<div class="father">
<div class="print ref="printnode">Here is something to print!</div>
</div>

scss样式
样式丢失的情况:

.father{
.print{
color:red;
}
}

样式正常的情况:

.father{
}
.print{
color:red;
}

总结

目前可以在使用时写根选择器样式解决,希望后续能修复此问题。

更改writeIframe方法:

更改writeIframe方法:
writeIframe: function (content) {
var w, doc, iframe = document.createElement('iframe'),
f = document.body.appendChild(iframe);
var style = document.createElement("style");
style.type = "text/css";
try {
style.appendChild(document.createTextNode("@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"));
} catch (ex) {
style.styleSheet.cssText = "@page{margin:0mm;@top-left{display: none;}@bottom-center{display: none;}}"; //针对IE
}
iframe.id = "myIframe";
//iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;";
iframe.setAttribute('style', 'position:absolute;width:0;height:0;top:-10px;left:-10px;');
w = f.contentWindow || f.contentDocument;
doc = f.contentDocument || f.contentWindow.document;
var head = doc.getElementsByTagName("head")[0];
// head.appendChild(style);
doc.open();
doc.write(content);
doc.close();
var _this = this
iframe.onload = function () {
_this.toPrint(w);
setTimeout(function () {
document.body.removeChild(iframe)
}, 100)
}
},

Originally posted by @quqingfei in #14 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.