欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Print.Js網(wǎng)頁(yè)打印標(biāo)簽詳細(xì)代碼示例

 更新時(shí)間:2025年06月28日 08:54:13   作者:許多寶滴IT  
Print.js一個(gè)小的javascript庫(kù),可幫助您從網(wǎng)絡(luò)上打印,這篇文章主要介紹了Print.Js網(wǎng)頁(yè)打印標(biāo)簽的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下

1、功能背景需求

后臺(tái)讀取數(shù)據(jù),預(yù)覽頁(yè)面再打印出小標(biāo)簽,涉及打印機(jī)設(shè)置紙張大小,與代碼編寫(xiě)兼容等等

2、打印機(jī)設(shè)置紙張大?。?/h2>

按照下圖順序設(shè)置需要打印的紙張大小,例如50mm*50mm

不知道,問(wèn)產(chǎn)品打印的紙張大小是多少,再去設(shè)置!

3、相關(guān)代碼(PrintJS)

代碼頁(yè)面要準(zhǔn)備一個(gè)預(yù)覽頁(yè)面,PrintJS打印時(shí)要綁定ID去打印。

3.1預(yù)覽打印效果圖:

3.2相關(guān)代碼:

<template>
  <!-- 網(wǎng)頁(yè)打印小票預(yù)覽頁(yè) -->
  <div class="tick">
    <div class="tick-bg">
      <div id="print-tick">
        <div class="tick-bg-content" v-for="(item, index) in 1" :key="index">
          <div class="header">
            <b class="header-title">酸菜豬肉燉粉條長(zhǎng)名就換行顯示..</b>
            <div class="header-price">
              <span>¥10.00</span>
              <span class="header-price-num">1份</span>
            </div>
          </div>
          <div class="body-address">住院部6F新生兒內(nèi)科②[番禺院區(qū)1]</div>
          <div class="footer">
            <div class="footer-flex">
              <span class="userName">張三</span>
              <span>1802****704</span>
            </div>
            <div class="footer-page">{{ index+1 }}/2</div>
          </div>
        </div>
      </div>

      <el-button class="w-80 ps-origin-btn" size="mini" @click="convertToImageAndPrint">打印</el-button>
    </div>
  </div>
</template>

<script>
import print from 'print-js'

export default {
  created() {
    this.type = this.$route.query.type
    this.printList = JSON.parse(localStorage.printList)
    console.log('this.printList', this.printList)
  },
  data() {
    return {
      type: 'takeaway',
      printList: []
    }
  },
  methods: {
    // 確認(rèn)打印
    convertToImageAndPrint() {
      print({
        printable: 'print-tick',
        type: 'html',
        scanStyles: false,
        // style: '@media print { body { margin: 0; padding: 0;}  .print-tick { margin: 0 auto; width: 100%;} }',
        css: 'data:text/css,' + encodeURIComponent(this.rechargeStyle())
      })
    },
    // 打印樣式
    rechargeStyle() {
      return `
        @page {
          width: 100%;
          margin: 0 !important;
          padding: 0 !important;
          box-sizing: border-box !important;
        }
        *, body {
          width: 100% !important;
          margin: 0 !important;
          padding: 0 !important;
          box-sizing: border-box !important;
          font-size: 16px !important;
        }
        #print-tick .tick-bg-content{
          padding: 0 18px !important;
        }
        #print-tick .header {
          width: 100% !important;
          padding-bottom: 5px !important;
          margin-bottom: 5px !important;
          border-bottom: 2px dashed #000 !important;
        }
        #print-tick .header .header-title{
          font-weight: bold !important;
          font-size: 18px !important;
          display: -webkit-box !important;
          display: -moz-box !important;
          overflow: hidden !important;
          line-clamp: 2 !important;
          -webkit-box-orient: vertical !important;
          -webkit-line-clamp: 2 !important;
          -moz-box-orient: vertical !important;
          -moz-line-clamp: 2 !important;
        }
        #print-tick .header .header-price{
          display: flex !important;
        }
        #print-tick .header-price .header-price-num{
          display: inline-block;
          padding-left: 10px;
        }
        #print-tick .body-address{
          width: 100% !important;
          margin-bottom: 5px !important;
          display: -webkit-box !important;
          display: -moz-box !important;
          overflow: hidden !important;
          line-clamp: 2 !important;
          -webkit-box-orient: vertical !important;
          -webkit-line-clamp: 2 !important;
          -moz-box-orient: vertical !important;
          -moz-line-clamp: 2 !important;
        }
        #print-tick .footer{
          padding-top: 5px !important;
          border-top: 2px dashed #000 !important;
        }
        #print-tick .footer .footer-flex{
          width: 100% !important;
          display: flex !important;
          justify-content: space-between !important;
          align-items: center !important;
        }
        #print-tick .footer .footer-page{
          display: flex !important;
          justify-content: end !important;
          padding-top: 10px !important;
        }

        @-moz-document url-prefix() {
          *, body {
            letter-spacing: -1px !important;
            width: 100% !important;
            margin: 0 !important;
            padding: 0 !important;
            box-sizing: border-box !important;
            font-size: 16px !important;
          }
          #print-tick .tick-bg-content {
            padding:0 0 0 30px !important;
          }
          #print-tick .header .header-price{
            display: flex !important;
            margin-top: 10px !important;
          }
        }
      `
    }
  }
}
</script>

<style lang="scss" scoped>
.tick {
  &-bg {
    background-color: grey;
    min-height: 100vh;
    width: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    #print-tick {
      font-size: 12px;
      line-height: 16px;
      font-weight: 500;
      .tick-bg-content {
        padding: 20px;
        margin: 0 auto;
        width: 290px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
        margin-bottom: 20px;
        .header {
          width: 100%;
          padding-bottom: 10px;
          margin-bottom: 10px;
          border-bottom: 2px dashed #dddddd;
          .header-title {
            display: -webkit-box !important;
            display: -moz-box !important;
            overflow: hidden !important;
            line-clamp: 2 !important;
            -webkit-box-orient: vertical !important;
            -webkit-line-clamp: 2 !important;
            -moz-box-orient: vertical !important;
            -moz-line-clamp: 2 !important;
          }
          .header-price {
            // margin-top: 10px;
            // transform: translate(100%, 0);
            // width: 50%;
            // display: flex;
            // justify-content: space-between;
            // align-items: center;
          .header-price-num{
              margin-top: 10px;
              display: inline-block;
              padding-left: 50px;
            }
          }
        }
        .body-address {
          width: 100%;
          margin-bottom: 10px;
          display: -webkit-box !important;
          -webkit-box-orient: vertical !important;
          -webkit-line-clamp: 2 !important;
          line-clamp: 2 !important;
          overflow: hidden !important;
        }
        .footer {
          width: 100%;
          border-top: 2px dashed #ddd;
          padding-top: 10px !important;
          .footer-flex {
            display: flex;
            justify-content: space-between;
            align-items: center;
          }
          .footer-page {
            padding-top: 10px;
            display: flex;
            justify-content: end;
            align-items: center;
          }
        }
      }
    }
  }
}
</style>

以上關(guān)鍵點(diǎn)在于print()打印的方法,可能要注意的是打印時(shí)的樣式調(diào)整,每個(gè)瀏覽器要處理下樣式兼容問(wèn)題,火狐比較特殊點(diǎn),也做了打印時(shí)的樣式特殊處理如下:

@-moz-document url-prefix() {
          *, body {
            letter-spacing: -1px !important;
            width: 100% !important;
            margin: 0 !important;
            padding: 0 !important;
            box-sizing: border-box !important;
            font-size: 16px !important;
          }
          #print-tick .tick-bg-content {
            padding:0 0 0 30px !important;
          }
          #print-tick .header .header-price{
            display: flex !important;
            margin-top: 10px !important;
          }
        }

3.3點(diǎn)擊打印時(shí),會(huì)彈出:

4、總結(jié):

網(wǎng)頁(yè)打印其實(shí)就是設(shè)置好打印設(shè)備,調(diào)試好機(jī)器,代碼方面寫(xiě)一個(gè)預(yù)覽頁(yè)面,用插件PrintJs就好,其他有問(wèn)題再慢慢調(diào)試就行。

到此這篇關(guān)于Print.Js網(wǎng)頁(yè)打印標(biāo)簽的文章就介紹到這了,更多相關(guān)PrintJs網(wǎng)頁(yè)打印標(biāo)簽內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 淺談webpack打包過(guò)程中因?yàn)閳D片的路徑導(dǎo)致的問(wèn)題

    淺談webpack打包過(guò)程中因?yàn)閳D片的路徑導(dǎo)致的問(wèn)題

    下面小編就為大家分享一篇淺談webpack打包過(guò)程中因?yàn)閳D片的路徑導(dǎo)致的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • JavaScript中防抖和節(jié)流的原理和區(qū)別詳解

    JavaScript中防抖和節(jié)流的原理和區(qū)別詳解

    JavaScript 中,防抖和節(jié)流是一種用于優(yōu)化事件處理函數(shù)調(diào)用頻率的技術(shù),防抖和節(jié)流的目的都是為了避免頻繁地觸發(fā)事件處理函數(shù),從而減少瀏覽器和服務(wù)器的負(fù)擔(dān),本文將給大家介紹一下JavaScript中防抖和節(jié)流的原理和區(qū)別,需要的朋友可以參考下
    2023-09-09
  • Bootstrap網(wǎng)格系統(tǒng)詳解

    Bootstrap網(wǎng)格系統(tǒng)詳解

    bootstrap框架中的網(wǎng)格系統(tǒng)就是將容器平分成12份,在使用的時(shí)候可以根據(jù)實(shí)際情況重新編譯LESS/SASS源碼來(lái)修改12這個(gè)數(shù)值。接下來(lái)通過(guò)本文給大家介紹Bootstrap網(wǎng)格系統(tǒng),感興趣的朋友一起學(xué)習(xí)
    2016-04-04
  • Js中Symbol的靜態(tài)屬性及用途詳解

    Js中Symbol的靜態(tài)屬性及用途詳解

    JavaScript 語(yǔ)言在 ES6 規(guī)范中引入了 Symbol 類(lèi)型,它是一種原始數(shù)據(jù)類(lèi)型,用于創(chuàng)建唯一的標(biāo)識(shí)符,本文將介紹 Symbol 類(lèi)型的所有靜態(tài)屬性,并舉例說(shuō)明它們的用途和使用場(chǎng)景,希望對(duì)大家有所幫助
    2023-12-12
  • 微信小程序開(kāi)發(fā)實(shí)現(xiàn)消息推送

    微信小程序開(kāi)發(fā)實(shí)現(xiàn)消息推送

    這篇文章主要為大家詳細(xì)介紹了微信小程序開(kāi)發(fā)實(shí)現(xiàn)消息推送,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • js常用節(jié)點(diǎn)操作實(shí)例總結(jié)

    js常用節(jié)點(diǎn)操作實(shí)例總結(jié)

    這篇文章主要介紹了js常用節(jié)點(diǎn)操作,結(jié)合實(shí)例形式總結(jié)分析了JavaScript針對(duì)dom節(jié)點(diǎn)的遍歷、查找、創(chuàng)建、刪除、克隆等相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下
    2023-04-04
  • 使用pjax實(shí)現(xiàn)無(wú)刷新更改頁(yè)面url

    使用pjax實(shí)現(xiàn)無(wú)刷新更改頁(yè)面url

    pjax=pushState+ajax,相信用過(guò)github的同學(xué)都知道,github部分頁(yè)面采用了pjax這個(gè)項(xiàng)目來(lái)實(shí)現(xiàn)ajax無(wú)刷新加載的同時(shí)改變頁(yè)面url。一起來(lái)學(xué)習(xí)一下這個(gè)插件吧。
    2015-02-02
  • jquery獲取img的src值的簡(jiǎn)單實(shí)例

    jquery獲取img的src值的簡(jiǎn)單實(shí)例

    下面小編就為大家?guī)?lái)一篇jquery獲取img的src值的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-05-05
  • 讓DIV的滾動(dòng)條自動(dòng)滾動(dòng)到最底部的3種方法(推薦)

    讓DIV的滾動(dòng)條自動(dòng)滾動(dòng)到最底部的3種方法(推薦)

    下面小編就為大家?guī)?lái)一篇讓DIV的滾動(dòng)條自動(dòng)滾動(dòng)到最底部的3種方法(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-09-09
  • Electron實(shí)現(xiàn)應(yīng)用打包、自動(dòng)升級(jí)過(guò)程解析

    Electron實(shí)現(xiàn)應(yīng)用打包、自動(dòng)升級(jí)過(guò)程解析

    這篇文章主要介紹了Electron實(shí)現(xiàn)應(yīng)用打包、自動(dòng)升級(jí)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07

最新評(píng)論