使用vue-print-nb实现打印,radio样式修改

1.需求:使用A3纸打印试卷,选择使用vue-print-nb实现页面打印(修改后的图片效果)

2.问题:单选题/radio的样式html页面样式显示正常,但是打印预览时页面样式显示错位

3.解决办法:修改radio显示标签

print.vue(页面标签)

               <!-- 打印显示会错位 -->
               <!-- <el-radio-group v-if="questionItem.questionType == 1 || questionItem.questionType == 3">
                <el-radio type="radio" :label="detail.prefix">
                  <div v-html="detail.content"></div>
                </el-radio>
              </el-radio-group>  -->

              <!-- 打印显示正常 -->
              <div class="classRadioType" v-if="questionItem.questionType == 1 || questionItem.questionType == 3">
                <input class="classRadio" type="radio" :name="detail.prefix">
                  <div v-html="detail.content"></div> 
              </div> 

print.vue(打印样式)

.classRadioType{
    display: flex;
    font-size: 14px;
    .classRadio{
      display: none;
    }
  } 
  @page {
    padding: 35px 0px; 
  }
  @media print {
    .el-radio__input,.el-checkbox__input{
      display: none !important;
    }
    .el-radio__label,.el-checkbox__label{
      div{
        color: #000;
        p:nth-of-type(2){
          display: none !important;
        }
      }
    }
  }

printarea.js

// 处理input框
      if (item.tagName === 'INPUT') {
        // 除了单选框 多选框比较特别
        if (typeInput === 'radio' || typeInput === 'checkbox') {
          copiedInput.setAttribute('checked', item.checked);
          // 
        } else {
          copiedInput.value = item.value;
          copiedInput.setAttribute('value', item.value);
        }
        // 处理select
      } else if (typeInput === 'select') {

        selectCount++;
        for (let b = 0; b < ele.querySelectorAll('select').length; b++) {
          let select = ele.querySelectorAll('select')[b]; // 获取原始层每一个select
          !select.getAttribute('newbs') && select.setAttribute('newbs', b) // 添加标识
          if (select.getAttribute('newbs') == selectCount) {
            let opSelectedIndex = ele.querySelectorAll('select')[selectCount].selectedIndex;
            item.options[opSelectedIndex].setAttribute('selected', true);

          }
        }

总结:我理解的是printarea.js中处理radio样式的时间是根据tagName类型做的判断,但是之前使用的el-radio的标签上找不到INPUT属性,所以没有处理成功,可能理解不一定很正确,欢迎小伙伴指教!

tagName(补充)

vue-print-nb实现页面打印

vue实现打印功能的两种方法(参考)

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值