how do i connect this to vuejs
actually if you load printJS as global variable or injecting on js scope can use in this way
// Creating the vue object
var vuemethod = new Vue({
...
methods : {
print_pdf : function(url){
printJS({printable: url, type:'pdf', showModal:true});
}
}
});
// on html
<a v-on:click="print_pdf('/uri/to/pdf')" target="_blank">Ver PDF</a>
@renjfk Hey Ren, there isn't anything special about using the library with Vue. If you define it as a global variable, you can use it anywhere. As Jesús mentioned, you can just call the printJS function inside any Vue method.
If you installed the library using npm, here is one way to import and use it:
import printJS from 'print-js';
Then inside your Vue instance (and/or components):
methods: {
myMethod() {
printJS('myPdfFileUrl.pdf');
}
}
Most helpful comment
@renjfk Hey Ren, there isn't anything special about using the library with Vue. If you define it as a global variable, you can use it anywhere. As Jesús mentioned, you can just call the
printJSfunction inside any Vue method.If you installed the library using npm, here is one way to import and use it:
import printJS from 'print-js';Then inside your Vue instance (and/or components):