[Vue, Ali P8 teaches you personally

Programmer Soto 2021-08-08 20:16:33
vue ali p8 teaches personally


 ![ Insert picture description here ](https://s2.51cto.com/images/20210808/1628424256690507.jpg)

The core of front-end routing : change URL, But the page does not refresh as a whole

 Insert picture description here

[](

)URL Of hash

URL Of hash That is to say Anchor point (#), It's essentially a change window.location.href attribute

  • We can do this by assigning values directly location.hash To change href, But the page doesn't refresh

     Insert picture description here

[](

)HTML5 Of history Pattern (5 Kind of )

history Interface is HTML5 Newly added , It has five pattern changes URL Without refreshing the page

  • history.pushState()

     Insert picture description here

  • history.replaceState()

     Insert picture description here

  • history.go()

     Insert picture description here

Add :

  • history.back() Equivalent to history.go(-1)

  • history.forward() Equivalent to history.go(1)

  • These interfaces are equivalent to the forward and backward of the browser interface

vue-router

=============================================================================

At present, there are three popular frameworks in the front end , Each has its own routing implementation :

  • Angular Of ngRouter
  • React Of ReactRouter
  • Vue Of vue-router

vue-router yes Vue.js The official routing plug-in , It and Vue.js It's deeply integrated , Suitable for building single page applications

vue-router Official website : https://router.vuejs.org/zh/

vue-router It's based on Routing and components

  • Routing is used to set the access path , Mapping paths and components

  • stay vue-router In a single page application , The change of page path is the switch of components .

Installation and use vue-router


We have learned webpack, In the follow-up development, we mainly develop in an engineering way

install vue-router


npm install vue-router --save

  • 1.
  • 2.
  • 3.

Use it in modular Engineering ( Because it's a plug-in , So you can go through Vue.use() To install the routing function )

  • Import routing objects , And call Vue.use(VueRouter)

  • Create a routing instance , And incoming route mapping configuration

  • stay Vue The created routing instance is mounted in the instance

Use vue-router Steps for :

  • Create routing component

  • Configure route mapping : Component and path mapping relationships

  • Using routing : adopt <router-link> and <router-view>


Routing configuration generally does not need to be configured by yourself , It's all equipped in the scaffold , Focus on the use of routing .

  • <router-link>: The label is a vue-router Built in components in , It will be rendered as a <a> label

  • <router-view>: The tag will be based on the current path , Dynamic rendering of different components

  • The rest of the page , Like the title at the top / Navigation , Or some copyright information at the bottom will be related to <router-view> At the same level

  • When routing is switched , The switch is <router-view> Mounted components , Nothing else will change

     Insert picture description here

Routing effect :

 Insert picture description here

[](

) The default path for routing

By default , Go to the home page of the website , We hope <router-view> Rendering the content of the home page

  • How to make the path jump to the home page by default , also <router-view> Rendering the home page component ?

  • Configure pair in routing configuration '/' The mapping of paths ,redirect Is redirection

     Insert picture description here

[](

)HTML5 Of History Pattern

As we said earlier, there are two ways to change the path :

  • URL Of hash

  • HTML5 Of history

  • By default , The change of path uses URL Of hash

Can be configured to use HTML5 Of History Pattern , Reference resources Official documents

Road load by lazy


Official explanation : When you package and build an application ,Javascript The bag will get very big , Affects page loading . If we can divide the components corresponding to different routes into different code blocks , Then the corresponding component is loaded when the route is accessed , It's more efficient .

The main function of lazy route loading is : Package the components corresponding to the route into one by one js Code block , Only when this route is accessed , Load the corresponding component .

The effect of routing lazy loading :

 Insert picture description here


Lazy loading in code :

  • Mode one : combination Vue The asynchronous components and Webpack Code analysis of

const Home = resolve => { require.ensure(['../components/Home.vue'],
() => { resolve(require('../components/Home.vue')) })};

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • Mode two :AMD How to write it

const About = resolve => require(['../components/About.vue'], resolve);

  • 1.
  • 2.
  • 3.
  • Mode three : Use ES6 Grammar to organize Vue Asynchronous components and Webpack Code segmentation for

const Home = () => import('../components/Home.vue')

  • 1.
  • 2.
  • 3.

Nested Route


Nested routing is a very common feature ,

  • For example home On the page , Hope to pass /home/news and /home/message Visit some content

  • A path maps to a component , Accessing these two paths will also render two components separately

     Insert picture description here

Two steps to implement nested routing :

  • Create the corresponding sub component , And configure the corresponding sub route in the routing map

  • Use... Inside the component <router-view> label


Nested routing examples :

  1. Define two components

     Insert picture description here

  2. Use router-link and router-view Show subcomponents

     Insert picture description here

  3. Configure the routing

     Insert picture description here

  4. Show the effect

     Insert picture description here


[](

) Default path for nested routes

Nested routes can also be configured with default paths , The configuration is as follows :

 Insert picture description here

Routing parameters


There are two main types of passing parameters :params and query

params The type of

  • Configure routing format :/router/:id

  • The way of transmission : stay path Follow the corresponding value

  • The path formed after transmission :/router/123,/router/abc

query The type of

  • Configure routing format :/router, It's a normal configuration

  • The way of transmission : Use in object query Of key As a means of delivery

  • The path formed after transmission :/router?id=123,/router?id=abc

Two ways of use :

  • <router-link>

     Insert picture description here

  • JavaScript Code mode

     Insert picture description here

$route To obtain parameters


Get parameters by $route Object acquired

In the use of the vue-router The application of , Routing objects are injected into each component , The assignment is this.$route, And when the route switches , The routing object is updated .

adopt $route The information to be transmitted is as follows :

 Insert picture description here

$route and $router The difference between :

  • $router by VueRouter example , Want to navigate to different URL, Use $router.push Method
  • $route by At present router Jump object , You can get name、path、query、params etc.

Finally, share a wave ,Java Advanced knowledge points of core architecture

In fact, success in an interview is inevitable , Because I've done enough preparation before that , It's not just about writing questions , More will go to brush some Java Advanced knowledge points of core architecture , such as :JVM、 High concurrency 、 Multithreading 、 cache 、Spring relevant 、 Distributed 、 Microservices 、RPC、 The Internet 、 Design patterns 、MQ、Redis、MySQL、 Design patterns 、 Load balancing 、 Algorithm 、 data structure 、kafka、ZK、 Cluster etc. . And all of these have been condensed into one pdf——《Java Advanced knowledge points of core architecture 》, All are the cream of the essence. , In a win-win mentality , Good things should be shared

image

image

image

There are many contents , Space is limited , This is not too much introduction , According to the above screenshots, you can make up your own mind , But this one 《Java Advanced knowledge points of core architecture pdf》 And the front P8 The whole set of interview questions can be shared with you for free , Click here to get all the information in the article for free

版权声明
本文为[Programmer Soto]所创,转载请带上原文链接,感谢
https://qdmana.com/2021/08/20210808201536425o.html

  1. HTML + CSS + JavaScript to achieve cool Fireworks (cloud like particle text 3D opening)
  2. HTML + CSS + JavaScript realizes 520 advertising love tree (including music), which is necessary for programmers to express themselves
  3. Solve the problem of Web front-end deployment server (it can be deployed online without a server)
  4. HTML + CSS + JS make wedding countdown web page template (520 / Tanabata Valentine's Day / programmer advertisement)
  5. What else can driverless minibus do besides "Park connection"?
  6. Cloud native leads the era of all cloud development
  7. NRM mirror source management tool
  8. Bring it to you, flex Jiugong
  9. Lolstyle UI component development practice (II) -- button group component
  10. Deconstruction assignment in ES6
  11. Luo 2 peerless Tang clan was officially launched. The official gave a key point, and the broadcast time was implied
  12. 20初识前端HTML(1)
  13. 当新零售遇上 Serverless
  14. 20 initial knowledge of front-end HTML (1)
  15. When new retail meets serverless
  16. [golang] - go into go language lesson 5 type conversion
  17. [golang] - go into go language lesson 6 conditional expression
  18. HTML5(八)——SVG 之 path 详解
  19. HTML5 (8) -- detailed explanation of SVG path
  20. 需要开通VIP以后页面内容才能复制怎么办?控制台禁用javascript即可
  21. Web前端|CSS入门教程(超详细的CSS使用讲解,适合前端初学者)
  22. 实践积累 —— 用Vue3简单写一个单行横向滚动组件
  23. Serverless 全能选手,再下一城
  24. What if you need to open a VIP to copy the page content? Just disable JavaScript on the console
  25. Web front end | CSS introductory tutorial (super detailed CSS explanation, suitable for front-end beginners)
  26. Practice accumulation - write a single line horizontal scroll component simply with vue3
  27. Dili Reba is thin again. She looks elegant and high in a strapless hollow skirt, and her "palm waist" is beautiful to a new height
  28. Serverless all-round player, next city
  29. The difference between MySQL semi synchronous replication and lossless semi synchronous replication
  30. Vue表单设计器的终极解决方案
  31. The ultimate solution for Vue form designer
  32. Nginx从理论到实践超详细笔记
  33. Yu Shuxin's red backless swimsuit is split to the waist and tail, with a concave convex figure and excessive color matching, and his face is white to dazzling
  34. Nginx ultra detailed notes from theory to practice
  35. 【动画消消乐|CSS】086.炫酷水波浪Loading过渡动画
  36. typecho全站启用https
  37. CCTV has another popular employee. The off-site interpretation is very professional, and the appearance ability is no less than that of Wang Bingbing
  38. [animation Xiaole | CSS] 086. Cool water wave loading transition animation
  39. Enable HTTPS in Typecho
  40. 50天用JavaScript完成50个web项目,我学到了什么?
  41. 根据JavaScript中原生的XMLHttpRequest实现jQuery的Ajax
  42. What have I learned from completing 50 web projects with JavaScript in 50 days?
  43. "My neighbor doesn't grow up" has hit the whole network. There are countless horse music circles, and actor Zhou Xiaochuan has successfully made a circle
  44. 根据JavaScript中原生的XMLHttpRequest实现jQuery的Ajax
  45. Implement the Ajax of jQuery according to the native XMLHttpRequest in JavaScript
  46. Implement the Ajax of jQuery according to the native XMLHttpRequest in JavaScript
  47. 30 + women still wear less T-shirts and jeans. If they wear them like stars, they will lose weight
  48. 数栈技术分享前端篇:TS,看你哪里逃~
  49. Several stack technology sharing front end: TS, see where you escape~
  50. 舍弃Kong和Nginx,Apache APISIX 在趣链科技 BaaS 平台的落地实践
  51. Abandon the landing practice of Kong and nginx, Apache apisik on the baas platform of fun chain technology
  52. 浪迹天涯king教你用elementui做复杂的表格,去处理报表数据(合并表头,合并表体行和列)
  53. 前端HTML两万字图文大总结,快来看看你会多少!【️熬夜整理&建议收藏️】
  54. Wandering around the world king teaches you to use elementui to make complex tables and process report data (merge header, merge table body rows and columns)
  55. 路由刷新数据丢失 - vuex数据读取的问题
  56. Front end HTML 20000 word graphic summary, come and see how much you can【 Stay up late to sort out & suggestions]
  57. Route refresh data loss - vuex data reading problem
  58. Systemctl系统启动Nginx服务脚本
  59. Systemctl system startup nginx service script
  60. sleepless