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
axiosinto the project:npm install --save axios
- To inject
axiosas a property onthiscomponent instances, create asrc/plugins/axios.jsplugin file that, oninstall, will mean component instances have anaxiosproperty: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
baseUrlinto all our components. We will create a plugin inline of thesrc/main.jsfile to do this:const...