vue实现打印功能最简单的方法

一、下载打印插件

通过这个地址下载vue打印插件:https://github.com/xyl66/vuePlugs_printjs ,下载完毕后,在src下新建文件夹plugs,将下载的插件print.js放到plugs文件夹里

二、全局注册打印插件

在main.js里注册打印插件,注册完成后,就可以在组件中使用了,main.js里的代码如下:

// vue 打印插件
import Print from '@/plugs/print'
Vue.use(Print) 

三、使用打印插件

全局注册完打印插件后,我们就可以在组件中使用它了,具体使用方法如下:

html部分:

js部分:

methods: {
    // 打印
    start_print(){
        this.$print(_this.$refs.print);//$refs的值要和html里的ref一致
    }
}

 

你可能感兴趣的:(vue)