Home Web Front-end JS Tutorial Detailed explanation of SPA single page application in vue

Detailed explanation of SPA single page application in vue

Apr 14, 2018 pm 05:08 PM
app Detailed explanation page

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>
Copy after login
③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 
  })
Copy after login
⑤Test

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


 
 
 
  

  
 
 
 

    

{{msg}}

    <router-view></router-view>   

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


 
 
 SPA练习
  
  
 
 
 

    

{{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、指定一个盛放代码片段的容器           &lt;router-view&gt;&lt;/router-view&gt;   */     var testCollect = Vue.component("collect",{       template:`         <p>           <h1>这是收藏页</h1>         </p>       `     })     var testDetail = Vue.component("detail",{       template:`         <p>           <h1>这是详情页</h1>         </p>       `     })     var testOrder = Vue.component("order",{       template:`         <p>           <h1>这是订单页</h1>         </p>       `     })     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>  
Copy after login
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 of this Website
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

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)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Unable to save changes to Photos app error in Windows 11 Unable to save changes to Photos app error in Windows 11 Mar 04, 2024 am 09:34 AM

If you encounter the Unable to save changes error while using the Photos app for image editing in Windows 11, this article will provide you with solutions. Unable to save changes. An error occurred while saving. Please try again later. This problem usually occurs due to incorrect permission settings, file corruption, or system failure. So, we’ve done some deep research and compiled some of the most effective troubleshooting steps to help you resolve this issue and ensure you can continue to use the Microsoft Photos app seamlessly on your Windows 11 device. Fix Unable to Save Changes to Photos App Error in Windows 11 Many users have been talking about Microsoft Photos app error on different forums

Photos cannot open this file because the format is not supported or the file is corrupted Photos cannot open this file because the format is not supported or the file is corrupted Feb 22, 2024 am 09:49 AM

In Windows, the Photos app is a convenient way to view and manage photos and videos. Through this application, users can easily access their multimedia files without installing additional software. However, sometimes users may encounter some problems, such as encountering a "This file cannot be opened because the format is not supported" error message when using the Photos app, or file corruption when trying to open photos or videos. This situation can be confusing and inconvenient for users, requiring some investigation and fixes to resolve the issues. Users see the following error when they try to open photos or videos on the Photos app. Sorry, Photos cannot open this file because the format is not currently supported, or the file

How to connect Apple Vision Pro to PC How to connect Apple Vision Pro to PC Apr 08, 2024 pm 09:01 PM

The Apple Vision Pro headset is not natively compatible with computers, so you must configure it to connect to a Windows computer. Since its launch, Apple Vision Pro has been a hit, and with its cutting-edge features and extensive operability, it's easy to see why. Although you can make some adjustments to it to suit your PC, and its functionality depends heavily on AppleOS, so its functionality will be limited. How do I connect AppleVisionPro to my computer? 1. Verify system requirements You need the latest version of Windows 11 (Custom PCs and Surface devices are not supported) Support 64-bit 2GHZ or faster fast processor High-performance GPU, most

How to copy a page in Word How to copy a page in Word Feb 20, 2024 am 10:09 AM

Want to copy a page in Microsoft Word and keep the formatting intact? This is a smart idea because duplicating pages in Word can be a useful time-saving technique when you want to create multiple copies of a specific document layout or format. This guide will walk you through the step-by-step process of copying pages in Word, whether you are creating a template or copying a specific page in a document. These simple instructions are designed to help you easily recreate your page without having to start from scratch. Why copy pages in Microsoft Word? There are several reasons why copying pages in Word is very beneficial: When you have a document with a specific layout or format that you want to copy. Unlike recreating the entire page from scratch

MS Paint not working properly in Windows 11 MS Paint not working properly in Windows 11 Mar 09, 2024 am 09:52 AM

Microsoft Paint not working in Windows 11/10? Well, this seems to be a common problem and we have some great solutions to fix it. Users have been complaining that when trying to use MSPaint, it doesn't work or open. Scrollbars in the app don't work, paste icons don't show up, crashes, etc. Luckily, we've collected some of the most effective troubleshooting methods to help you resolve issues with Microsoft Paint app. Why doesn't Microsoft Paint work? Some possible reasons why MSPaint is not working on Windows 11/10 PC are as follows: The security identifier is corrupted. hung system

Shazam app not working in iPhone: Fix Shazam app not working in iPhone: Fix Jun 08, 2024 pm 12:36 PM

Having issues with the Shazam app on iPhone? Shazam helps you find songs by listening to them. However, if Shazam isn't working properly or doesn't recognize the song, you'll have to troubleshoot it manually. Repairing the Shazam app won't take long. So, without wasting any more time, follow the steps below to resolve issues with Shazam app. Fix 1 – Disable Bold Text Feature Bold text on iPhone may be the reason why Shazam is not working properly. Step 1 – You can only do this from your iPhone settings. So, open it. Step 2 – Next, open the “Display & Brightness” settings there. Step 3 – If you find that “Bold Text” is enabled

Move photos from old Photos to the new Photos app in Windows 11 Move photos from old Photos to the new Photos app in Windows 11 Mar 10, 2024 am 09:37 AM

This article will guide you on how to migrate photos from Photos Legacy to the new Photos app in Windows 11. Microsoft has introduced a revamped Photos app in Windows 11, giving users a simpler and more feature-rich experience. The new Photos app sorts photos differently than the past PhotosLegacy app. It organizes photos into folders like other Windows files instead of creating albums. However, users still using the Photos Legacy app can easily migrate their photos to the new version of Microsoft Photos. What is Phot

Detailed explanation of obtaining administrator rights in Win11 Detailed explanation of obtaining administrator rights in Win11 Mar 08, 2024 pm 03:06 PM

Windows operating system is one of the most popular operating systems in the world, and its new version Win11 has attracted much attention. In the Win11 system, obtaining administrator rights is an important operation. Administrator rights allow users to perform more operations and settings on the system. This article will introduce in detail how to obtain administrator permissions in Win11 system and how to effectively manage permissions. In the Win11 system, administrator rights are divided into two types: local administrator and domain administrator. A local administrator has full administrative rights to the local computer

See all articles