On-demand import of vuant-UI

  • First configure it in the babel.config.js file:
Before configuration remember introduction: NPM I Babel - plugin - import - D module. Exports = {presets: ["@vue/cli-plugin-babel/preset"], // Vant introduces plugins on demand: [[" import", {libraryName: "vant", libraryDirectory: "es", style: true, }, "vant", ], ], }Copy the code
  • Then import as needed in the entry file main.js
Import "vant/lib/index.css" import {Button} from 'vant' vue.use (Button)Copy the code
  • To avoid the chaos of main.js caused by the increasing number of components imported on demand, we can create a NEW JS file to store the imported on demand, and then import the file into main.js

Vue scaffolding setup automatically launches the browser

Module. exports = {devServer: {// automatically open browser open: true,},}Copy the code