Let's create a project that uses a RESTful API and the routing concepts that we've just learned. Create a new project by running the following in your Terminal:
# Create a new Vue project $ vue init webpack-simple vue-spa # Navigate to directory $ cd vue-spa # Install dependencies $ npm install # Install Vue Router and Axios $ npm install vue-router axios # Run application $ npm run dev
We can start off by enabling the VueRouter
plugin within our application. To do this, we can create a new file inside src/router
named index.js
. We'll use this file to contain all the router-specific configuration, but we'll separate out each route into different files depending on the underlying feature.
Let's import and add the router plugin:
import Vue from 'vue'; import VueRouter from 'vue-router'; Vue.use(VueRouter)