diff --git a/src/utils/print.js b/src/utils/print.js index a3e26a45..fb6d422b 100644 --- a/src/utils/print.js +++ b/src/utils/print.js @@ -8,7 +8,13 @@ const Print = function(dom, options) { }, options); if ((typeof dom) === "string") { - this.dom = document.querySelector(dom); + try{ + this.dom = document.querySelector(dom); + }catch{ + var createDom = document.createElement("div") + createDom.innerHTML = dom + this.dom = createDom; + }; } else { this.isDOM(dom) this.dom = this.isDOM(dom) ? dom : dom.$el; @@ -36,7 +42,7 @@ Print.prototype = { } str += ""; - + str += ""; return str; }, diff --git a/src/views/vab/print.vue b/src/views/vab/print.vue index 361acb9d..f10505d8 100644 --- a/src/views/vab/print.vue +++ b/src/views/vab/print.vue @@ -3,12 +3,13 @@ - + 普通打印
- 打印内容 -

忽略打印

+
打印内容1

忽略打印

+
+
打印内容2
@@ -35,8 +36,7 @@ }, print2(){ //创建虚拟DOM结构后再传入 - var dom = document.createElement("div") - dom.innerHTML = "
后创建的DOM结构
" + var dom = "

TITLE

后创建的DOM结构

" print(dom) } } @@ -44,6 +44,6 @@