The second step, Vue Router installation and use



The Vue development environment has been built in the first step, now

Install and use VUE router for dynamic routing.

The first step is to install vue router:

Open cmd and enter the working directory, which is the folder where firstVue is located, and enter the command to install vue router: npm install vue-router


After the installation is complete, start using vue router:

①We create a new folder and name it view, and then create a new test.vue under the folder:



② Go to router文件夹下 " index.js文件 " Open and enter:

Note: Since @/components/HelloWorld is quoted but not used, an error may be reported. You can delete import HelloWorld from...


③ then test.vue components knock:

$route.params.testId Is to get the parameters of the current route.
④Open cmd and enter npm run dev in the firstVue directory:

Then display after success:


Enter into the browser: http://localhost:8080/#/test/123 display:


Successfully install and use routing.


Next practice:

① Modify index.js routing file:


②Modify the test.vue file:


③Open cmd, enter npm run dev in the firstVue directory, and then enter into the browser: http://localhost:8080/#/test/123/name/xxx shows:


carry out.




Guess you like

Origin blog.csdn.net/li__po/article/details/80449788