[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<>认识路由
先创建一个vue-cli2项目,use vue-router
略…
<>前端渲染 后端渲染 前端路由 后端路由
<>后端渲染
* jsp: (java server page) = html+css+java代码(动态从数据库读取数据)
* 服务器端已经渲染好了,网页已经渲染好了,然后发送给前端
* 服务器端直接生产渲染号对象的html页面,返回给客户端进行展示
* URL会发送给服务器,服务器会通过正则对该url进行匹配,并且最后交给一个controller进行处理
* controller进行各种处理,最终生成HTML或者数据返回给终端
* php
这种情况下渲染号的页面,不需要单独加载任何js和css,可以直接交给浏览器展示,这样也有利于SEO的优化
缺点:
* 所有的东西都是由后端人员来编写和维护的
* 前端开发人员需要通过php和java等语言来编写页面代码
* HTML代码和数据以及对应的逻辑会混在一起,编写和维护都很糟糕
<>后端路由
后端处理URL和页面之间的映射关系
<>前后端分离阶段
* 后端只负责提供数据,不负责任何界面的内容
* 输入URL后,去静态资源服务器拿html+css+js,js代码由浏览器执行
* 当执行ajax后,向服务器获取数据后,通过JS渲染HTML和CSS
* 浏览器中显示的网页大部分内容,都是由前端写的js代码在浏览器中执行,最终渲染处来网页
优点:
* 前后端责任清晰,后端专注数据
* 后端服务器并不关心,前端是ios,web,android…,依然使用之前的一套API即可
<>单页面富应用阶段 SPA
前端路由阶段:
一个url映射一个组件,前端路由管理映射关系
url --> 页面的映射关系,后端不管了!!!
* SPA最重要的特点就是在前后端的基础上加上了一层前端路由
* 也就是前端来维护一套路由的规则
前端路由的核心
* 改变URL,但是页面不进行整体刷新
* 如何实现呢?
<>URL的hash
location.hash = 'url'
<>history.pushState({},’’,‘home’)
history.back()出栈
history.replaceState() 自己不能访问
histroy.go(-1) 等于 history.back()
history.forward() 等于 history.go(1)
改变url,网页不刷新
history类似于栈结构,url显示的是栈顶元素!!!