1、下载插件
npm install vue-print-nb --save
2、全局注册(在main.js)中引入
//打印文件
import Print from 'vue-print-nb'
Vue.use(Print)
3、需要打印部分设置 id
<div id="single-info">
<el-form label-width="160px">
<el-row align="center" style="margin-top:30px;">
<el-col :span="24" align="center">
<el-button id="info-btn" v-print="'#single-info'" @click="prints">打印</el-button>
</el-col>
</el-row>
</el-form>
</div>
4、可为打印文件设置标题:
prints(){
var prints = document.getElementById('single-info');
prints.title = "打印的标题";
}
转载自:Vue打印文件(v-print)_lu_wei_shuai的博客-CSDN博客_vue打印文件