Custom Plugins
In this example we show how you how you can create your own plugin
In this example:
plugins/hello.js
- logs a message to the console with a dynamic message.
store/index.js
- stores our dynamic message from our input.
pages/index.vue
uses the hello plugin to:
- log a message to the console on mounted.
- log a message to the console containing the value from our input.
plugins/nuxt-api.js
- fetches data from our API.
pages/api-plugin.vue
- uses our plugin to fetch and show the data from our API.
nuxt.config.js
- registers our plugins using the plugins
property.
Learn more in the Directory Structure book in the plugins chapter.
Loading Sandbox...
Editer cette page sur GitHub
Mise à jour le Mon, July 12, 2021