5. Global Component Composition
Activity 5.01: Building a Vue.js Application with Plugins and Reusable Components
Solution:
Perform the following steps to complete the activity:
Note
To access the code files for this activity, refer to https://packt.live/35UlWpj.
- Install
axios
into the project:npm install --save axios
- To inject
axios
as a property onthis
component instances, create asrc/plugins/axios.js
plugin file that, oninstall
, will mean component instances have anaxios
property:import axios from 'axios' export default {   install(Vue) {     Vue.prototype.axios = axios   } }
- For the plugin to work, import and register it in
src/main.js
:// other imports import axiosPlugin from './plugins/axios.js' Vue.use(axiosPlugin) // other initialisation code
- We also want to inject our API's
baseUrl
into all our components. We will create a plugin inline of thesrc/main.js
file to do this:const...