移动端跳转服务端的H5页面的懒加载效果(前后端未分离)

最近在开发一个WebApp,思路很简单,就是用Hbuild做一个移动端的壳,再从这个壳跳转到服务端的页面(使用location.href,存在跨域)
开发过程中碰到一个问题,首次安装后跳转到服务端的页面需要加载css和js缓存,而这个过程可能需要耗时数秒钟,如果直接展示一个空白页的话用户体验不好。所以打算给这个壳的index页面加一个懒加载效果,但是由于使用location.href,跳转过程中大部分的动态效果(css跟动图)都处于卡顿状态,给人的感官极差。最后想了个折中的方案,通过iframe内嵌跳转页面,加载完成再进行展示,代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1  maximum-scale=1 user-scalable=no">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="HandheldFriendly" content="True">
<title>welcome</title>
<link rel="stylesheet" href="css/materialize.css">
<script src="js/jquery.min.js"></script>
<style>
body {
 margin: 0px;
 }
iframe {
border: 0px;
}
</style>
</head>
<body scroll="no">
<div class="container" id="container">
	<div class="section" style="padding-top: 10rem;">
	
	  <div class="row">
	    <div class="col s12 m4">
	    </div>
	
	    <div class="col s12 m4">
	      <div class="icon-block">
				<h2 class="center light-blue-text"><img src="img/profile.gif" alt="" class="z-depth-5" style="border-radius:0px;border: 0;width: 150px;    height: 150px;"></h2>
				<p class="center light">Just a moment......</p>
	      </div>
	    </div>
	
	    <div class="col s12 m4">
	    </div>
	  </div>
	
	</div>
</div>

<!--style="visibility: hidden"-->
<iframe id="iframe" name="iframe" frameborder="0" style="visibility: hidden" width="100%" height="100%" scrolling="auto"
src="http://134.175.153.50/trunk/index"></iframe> 
</body>
	<script type="text/javascript">
		$(function () {
			$("#iframe").load(function () {
				this.style.height=document.body.clientHeight;
				if($("#iframe").is(':visible')){
					$("#container").remove();
					$("#iframe").css("visibility","");
				}
			});
		});
	</script>
</html>

直接使用Hbuild开发前端页面就不会出现这类问题,但是由于目前项目还未改造成前后端分离的结构,所以只能采用这种写法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Spring Boot和Vue的前后端分离项目中,页面跳转的方式通常是通过前端路由来实现。Vue使用vue-router来进行路由管理,而Spring Boot作为后端提供数据接口。 首先,在Vue项目中配置路由。可以在main.js文件中引入vue-router,并创建路由实例,配置路由映射关系。例如: ```javascript import Vue from 'vue'; import VueRouter from 'vue-router'; Vue.use(VueRouter); const routes = [ { path: '/', name: 'Home', component: () => import('@/views/Home.vue'), }, { path: '/about', name: 'About', component: () => import('@/views/About.vue'), }, // 其他路由配置... ]; const router = new VueRouter({ mode: 'history', base: process.env.BASE_URL, routes, }); export default router; ``` 上面的代码定义了两个路由,分别对应根路径和/about路径,组件分别为Home和About。 接下来,在前端页面中使用`<router-link>`标签或编程式导航来实现页面跳转。例如: ```html <template> <div> <router-link to="/">Home</router-link> <router-link to="/about">About</router-link> <!-- 其他页面跳转链接... --> <router-view></router-view> </div> </template> ``` `<router-link>`标签会渲染成a标签,点击后会触发相应的路由跳转。 同时,在后端的Spring Boot项目中,需要配置跨域访问权限。可以通过添加`@CrossOrigin`注解来实现。例如: ```java @RestController @CrossOrigin public class ApiController { // 接口实现... } ``` 这样前端通过异步请求后端接口获取数据,再根据数据动态渲染页面。 总结起来,前后端分离项目中的页面跳转主要是通过前端路由来实现,Vue负责前端路由管理,Spring Boot负责后端数据接口提供。通过配置好的路由规则,前端页面可以实现无刷新的跳转页面内容更新。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值