Vue.js 3 Cookbook
上QQ阅读APP看书,第一时间看更新

Adding plugins to a Vue CLI project with Vue UI

The Vue UI tool is one of the most powerful additional tools for Vue development. It makes a developer's life easier, and at the same time can help manage the Vue projects.

Getting ready

The pre-requisite for this recipe is as follows:

  • Node.js 12+

The Node.js global objects that are required are as follows:

  • @vue/cli
  • @vue/cli-service-global

How to do it...

First, we need to create our Vue CLI project. To find how to create a Vue CLI project, please check the 'Creating your first project with Vue CLI' recipe. We can use the one we created in the last recipe or start a new one. Now, follow the instructions to add a plugin:

  1. Open the Vue UI interface. Open Terminal (macOS or Linux) or Command Prompt/PowerShell (Windows) and execute the following command:
> vue ui
  1. A new browser window will appear, with the Vue UI interface:

Here, you can list your projects, create a new project, or import an existing one.

  1. Now, we will import the one we created:

You need to find the folder that you created and click on Import this folder.

  1. After the folder is imported, the default Dashboard of the project will appear:

Here, it's possible to customize your Dashboard, adding new widgets, by clicking on the Customize button on the top:

  1. To add a new plugin, you must click on the Plugins menu in the left-hand sidebar:

The base plugins that you added on the Vue CLI tool will be already listed here. 

  1. Now, we will add the base Vue ecosystem plugins—vuex and vue-router:

  1. If you check your code, you will see that the main.js file was changed, and the vuex (store) and vue-router (router) plugins are now imported and injected to the Vue instance:

How it works...

The Vue UI plugins work in conjunction with npm or yarn to automatically install the packages on your project, and then inject—when possible—the necessary conditions on the Vue instance.

If a plugin is a visual, directive, or a non-direct instantiated plugin, the Vue UI will install it and manage it, but you need to import it for use on your application.