900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 实例讲述vue中SPA单页面应用程序

实例讲述vue中SPA单页面应用程序

时间:2021-11-15 00:51:49

相关推荐

实例讲述vue中SPA单页面应用程序

web前端|js教程

应用程序,页面,讲述

web前端-js教程

本文主要为大家详细介绍了vue中SPA单页面应用程序的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能帮助到大家。

仿好刷客tms平台源码,ubuntu更新地方,爬虫董事长,php技术设计管理信息系统教程,兴宁网站seolzw

A、SPA的概述

流程管理源码,vscode 正则匹配替换,ubuntu 卸载无线,ideal安装tomcat,sqlite3的时间类型,手机中了爬虫病毒怎么办,php排课系统,河北seo优化怎么推广,阅读主题网站的主题,flash网页下载中心,织梦模板文件描述乱码lzw

SPA(single page application)单页面应用程序,在一个完成的应用或者站点中,只有一个完整的html页面,这个页面有一个容器,可以把需要加载的代码片段插入到该容器中。

摄影作品源码,ubuntu验证显卡装好,不怕低温的爬虫,u php,seo快速唯独lzw

SPA的工作原理:

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

①根据地址栏中url解析完整的页面:index.html

加载index.html

②根据地址栏中url解析#后的路由地址: start

根据路由地址,去在当前应用的配置中 找该路由地址的配置对象去查找该路由地址 所对应的模板的页面地址

发起异步请求加载该页面地址

③把请求来的数据加载到指定的容器中

B、通过VueRouter来实现一个SPA的基本步骤

①引入对应的vue-router.js(该文件我已经上传到我的文件中)

②指定一个盛放代码片段的容器

③创建业务所需要的各个组件

④配置路由词典

每一个路由地址的配置对象(要加载哪个页面…)

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

⑤测试

在地址栏中 输入对应的不同的路由地址 确认是否能够加载对应的

{{msg}}

var testLogin = ponent("login",{template:`

这是我的登录页面

` }) var testRegister = ponent("register",{template:`

这是我的注册页面

` }) //配置路由词典 //对象数组 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"} })

SPA练习

{{msg}}

/* 需要大家创建一个SPA,这个SPA有3个组件,分别对应的是collect/detail/order 功能需求: 在地址栏中路由地址是: /myColllect --> 收藏页组件 /myDetail --> 详情页组件 /myOrder --> 订单页组件 */ /* 1、引入js文件 2、创建三个组件,需要返回值 3、路由词典配置(三小步)const myRoutes、const myRouter、router:myRouter, 4、指定一个盛放代码片段的容器 */ var testCollect = ponent("collect",{template:`

这是收藏页

` }) var testDetail = ponent("detail",{template:`

这是详情页

` }) var testOrder = ponent("order",{template:`

这是订单页

` }) 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"} })

简单了解vue2 单页面如何设置网页title

关于Vue.js如何操作单页面多路由区域的实例分析

H5单页面手势滑屏切换原理

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。