search
HomeWeb Front-endJS TutorialDetailed explanation of SPA single page application in vue

This time I will bring you a detailed explanation of the SPA single-page application in vue. What are the precautions when using the SPA single-page application in vue. The following is a practical case. Let’s take a look. .

1. Overview of SPA

SPA (single page application) is a single page application. In a completed application or site, there is only one complete HTML page. This page has a container into which the code snippets that need to be loaded can be inserted.

How SPA works:

eg: http://127.0.0.1/index.html#/start

① Parse the complete page according to the url in the address bar: index.html
 Load index.html

②According to the routing address after url parsing # in the address bar: start
 According to the routing address, find the configuration object of the routing address in the current application configuration to find the The page address of the template corresponding to the routing address  Initiate an asynchronous request to load the page address

③Load the requested data into the specified container

2. Basic steps to implement a SPA through VueRouter

①Introduce the corresponding vue-router.js (I have uploaded this file to my file)

②Specify a container to hold code snippets

<router-view></router-view>
③Create various components required for the business

④Configure routing dictionary
Configuration object of each routing address (which page to load...)

const myRoutes = [
  {path:'/myLogin',component:TestLogin},
  {path:'/myRegister',component:TestRegister}
  ]
  const myRouter = new VueRouter({
  routes:myRoutes 
  })
  new Vue({
    router:myRouter 
  })
⑤Test

Enter the corresponding different routing addresses in the address bar to confirm whether the corresponding

 
 
 
  <script></script>

  <script></script>
 
 
 

    

{{msg}}

    <router-view></router-view>      <script> var testLogin = Vue.component("login",{ template:` <p> <h1>这是我的登录页面 ` }) var testRegister = Vue.component("register",{ template:` <p> <h1>这是我的注册页面 ` }) //配置路由词典 //对象数组 const myRoutes =[ //当路由地址:地址栏中的那个路径是myLogin访问组件 //组件是作为标签来用的所以不能直接在component后面使用 //要用返回值        //path:&#39;&#39;指定地址栏为空:默认为Login页面         {path:&#39;&#39;,component:testLogin}, {path:&#39;/myLogin&#39;,component:testLogin}, {path:&#39;/myRegister&#39;,component:testRegister} ] const myRouter = new VueRouter({ //myRoutes可以直接用上面的数组替换 routes:myRoutes }) new Vue({ router:myRouter, //或者: /* router:new VueRouter({ routes:[ {path:&#39;/myLogin&#39;,component:testLogin}, {path:&#39;/myRegister&#39;,component:testRegister} ] }) */ el:"#container", data:{ msg:"Hello VueJs" } }) </script>  
nbsp;html>

 
 
 SPA练习
  <script></script>
  <script></script>
 
 
 

    

{{msg}}

    <router-view></router-view>      <script> /* 需要大家创建一个SPA,这个SPA有3个组件,分别对应的是collect/detail/order 功能需求: 在地址栏中路由地址是: /myColllect --> 收藏页组件 /myDetail --> 详情页组件 /myOrder --> 订单页组件 */ /* 1、引入js文件 2、创建三个组件,需要返回值 3、路由词典配置(三小步)const myRoutes、const myRouter、router:myRouter, 4、指定一个盛放代码片段的容器 <router-view> */ var testCollect = Vue.component("collect",{ template:` <p> <h1>这是收藏页 ` }) var testDetail = Vue.component("detail",{ template:` <p> <h1>这是详情页 ` }) var testOrder = Vue.component("order",{ template:` <p> <h1>这是订单页 ` }) const myRoutes = [ {path:"",component:testCollect}, {path:"/myColllect",component:testCollect}, {path:"/myDetail",component:testDetail}, {path:"/myOrder",component:testOrder}, ] const myRouter = new VueRouter({ routes:myRoutes }) new Vue({ router:myRouter, el:"#container", data:{ msg:"Hello VueJs" } }) </script>  
I believe you have mastered the method after reading the case in this article. Please come for more exciting information. Pay attention to other related articles on php Chinese website!

Recommended reading:

mint-ui loadmore Pull-up loading and pull-down refresh conflict handling method

How about the WeChat applet Make the image upload to the server

The above is the detailed content of Detailed explanation of SPA single page application in vue. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP实现MVVM架构:基本原理及应用PHP实现MVVM架构:基本原理及应用Jun 18, 2023 am 08:54 AM

随着Web应用程序的快速发展,越来越多的开发者将目光投向了各种新兴的Web开发框架和架构设计模式。其中一个备受瞩目的设计模式就是MVVM(ModelViewViewModel)架构模式。MVVM采用了一种现代化的设计模式,通过将UI和业务逻辑相分离,使得开发人员能够更好地管理和维护应用程序。此外,MVVM减少了不必要的耦合,提高了代码的可重用性和灵活性,

msedge.exe是什么应用程序msedge.exe是什么应用程序Sep 09, 2022 pm 02:37 PM

“msedge.exe”指的是“Microsoft Edge”网页浏览器软件;“Microsoft Edge”是由Microsoft开发的网页浏览器,该浏览器在2015年被正式命名,并且内置在了Windows10版本中;该浏览器与IE浏览器相比,Edge将支持现代浏览器功能,比如扩展。

卸载程序的文件名是什么卸载程序的文件名是什么Oct 21, 2022 pm 02:05 PM

卸载程序的文件名是“uninstall.exe”或“uninst.exe”,是用以协助使用者将软件自电脑中删除的一种电脑软件。使用方法:1、在文件资源管理器中挖掘并导航到应用程序EXE文件所在的文件路径;2、通过文件路径打开应用程序的安装目录,找到“uninstall.exe”文件;3、双击卸载文件“uninstall.exe”即可开始程序删除过程。

如何修复 Windows 11 上的应用程序无法打开问题 [已解决]如何修复 Windows 11 上的应用程序无法打开问题 [已解决]May 02, 2023 pm 12:40 PM

微软最新发布的Windows11,已经证明是Windows10的更好版本,其结构变化、更人性化、重新排列的任务栏等。尽管Windows11是其中一个优秀的版本。许多Windows用户注意到他们的Windows11PC上存在一个不寻常的问题,他们无法启动大多数Windows11应用程序。无论他们尝试启动应用程序多少次,它只是简单地崩溃并且无法在系统上打开。突然发生这种情况可能有很多原因,下面列出了一些原因。Windows更新服务已停止。对系统的病毒攻击。系统上的用户帐户存

explorer.exe应用程序错误如何解决explorer.exe应用程序错误如何解决Jun 21, 2023 pm 02:14 PM

explorer.exe应用程序错误的解决办法:1、按下键盘上的“win”+“R”组合键,再打开的运行窗口中输入命“inetcpl.cpl”;2、在上方选择“高级”选项卡,在下方点击“重置”;3、在弹出来的窗口中,勾选“删除个人设置”,勾选后点击下面的“重置”。如果以上操作无法解决问题,请检查电脑是否有木马,这个时候建议重装系统,安装一个原版或者纯净版的系统。

使用PHP和OpenLayers创建地图应用程序使用PHP和OpenLayers创建地图应用程序May 11, 2023 pm 08:31 PM

随着Internet的发展,越来越多的应用程序需要实现地图可视化展示。本文将介绍如何使用PHP和OpenLayers创建地图应用程序。一、OpenLayers介绍OpenLayers是一个JavaScript开源库,可以展示动态地图。除了展示标准的WMS、WFS和GoogleMaps,OpenLayers还可以展示自定义的地图,可以展示矢量数据,支持地图放

如何在 Windows 11 中重新安装邮件应用程序如何在 Windows 11 中重新安装邮件应用程序Apr 14, 2023 pm 03:19 PM

&lt;p&gt;&lt;strong&gt;邮件应用程序&lt;/strong&gt;是Windows11内置的一个非常有用的电子邮件客户端。它允许您从一个位置管理所有邮件帐户。虽然Mail应用程序非常有用,但有时可能需要重置,有时也需要重新安装,原因有多种。在本文中,我们将通过一些简单的步骤说明如何从Windows11轻松卸载Mail应用程序,以及如何轻松地从MicrosoftStore将其取回。&lt;/p&gt;&l

如何在应用程序防护中启用或禁用打印如何在应用程序防护中启用或禁用打印Apr 16, 2023 pm 01:55 PM

除了WindowsDefender和适用于Windows11的第三方防病毒工具之外,还有更多方法可以保护您的系统。MicrosoftDefenderApplicationGuard是Windows的功能之一,可以帮助您阻止病毒和恶意软件。尽管此功能在大多数用户的PC中非常受欢迎,但有些人可能会发现它受到限制,因为它可能会限制某些功能,例如打印。无论如何,在本文中,我们将根据您的需要向您展示如何启用或禁用它。什么是MicrosoftDefenderApplicationGuardMana

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools