Overview
The plugin system is built around thecreateVuePrintIt function, which returns a Vue plugin object that can be installed using app.use(). The plugin registers global methods and integrates seamlessly with Vue’s reactivity system.
Plugin Creation
ThecreateVuePrintIt function in plugin.ts:18 creates and configures the plugin:
Key Features
Global Configuration
Global Configuration
The plugin accepts global options that apply to all print operations throughout your app:These options serve as defaults and can be overridden per print operation.
Customizable Method Name
Customizable Method Name
You can customize the global method name using the By default, the method is named
globalMethodName option:$print.Bridge Integration
Bridge Integration
The plugin automatically detects if the bridge plugin is installed and conditionally adds bridge methods:This design ensures the core plugin works independently without requiring the bridge.
Global Properties Registration
Vue Print It registers methods onapp.config.globalProperties, making them accessible in all component instances:
Print Function Factory
ThecreatePrintFunction in usePrint.ts:306 is a factory that creates printing functions with bound global options:
Options Priority
The plugin implements a three-tier options system:- Default options - Hardcoded sensible defaults
- Global options - Set during plugin installation
- Local options - Passed to individual print calls
Composable Integration
TheusePrint composable provides the same functionality in Composition API:
- Uses the global plugin instance if available (ensures shared configuration)
- Falls back to a local instance if the plugin isn’t installed (useful for testing or standalone usage)
Architecture Benefits
Separation of Concerns
The plugin handles global registration while
createPrintFunction contains the core printing logic, making the codebase modular and testable.Progressive Enhancement
The plugin works standalone and automatically enhances itself when the bridge plugin is detected.
Flexible Configuration
Three-tier options system allows global defaults with per-call overrides.
Multiple Access Methods
Accessible via global properties (Options API), composable (Composition API), or direct function calls.
Installation Flow
Here’s what happens when you install the plugin:TypeScript Support
The plugin provides full TypeScript support with type definitions:Next Steps
Style Injection
Learn how styles are preserved during printing
Bridge Printing
Explore direct printer communication