Question presented to candidate:
"We want to ship our design system's toast notifications so that any app can turn them on with one line in main.ts. What is a Vue plugin, what can its install function do, and how would you make it work well with <script setup>?"
What a strong answer should cover:
- A plugin is an object with
install(app, ...options), or a plain function with the same signature;app.use(plugin, options)calls it once. installcan do anything the app instance allows:app.provide,app.config.globalProperties,app.component,app.directive,app.mixin(discouraged), and nestedapp.use.- Pair it with a composable (
useToast()that callsinject) so<script setup>code gets a typed API; the global property serves templates and Options API code. app.useis chainable and deduplicated: a second install of the same plugin is skipped with a dev warning, and options from the second call are ignored.- Vue 3.5 adds
app.onUnmount()so a plugin can release timers or connections when the app unmounts. - Real examples: Vue Router, Pinia, i18n libraries; for SSR, install on each per-request app.
Clarifying questions expected:
- "Will consumers use
<script setup>, the Options API, or both?" - "Does the plugin hold state? Then it must be created per app, not at module level, for SSR."
Code / implementation expected: Yes β a small plugin with install, a composable to consume it, and app.use in main.ts.