vue框架中如何让大屏页面自适应,方法是什么
Admin 2022-06-30 群英技术资讯 1179 次浏览
这篇文章主要介绍“vue框架中如何让大屏页面自适应,方法是什么”的相关知识,下面会通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“vue框架中如何让大屏页面自适应,方法是什么”文章能帮助大家解决问题。本文实例为大家分享了Vue实现大屏页面的屏幕自适应的具体代码,供大家参考,具体内容如下
1. 在配置文件设置大屏设计的尺寸1920*1080
//appConfig.js
export default{
screen:{
width:1920,
height:1080,
scale:20
}//大屏设计宽高
}
2. 定义resetScreenSize.js
import appConfig from '../config/base'
export function pageResize(callback) {
let init = () => {
console.log(window.innerHeight + "," + window.innerWidth);
let _el = document.getElementById('app');
let hScale = window.innerHeight / appConfig.screen.height;
let wScale = window.innerWidth / appConfig.screen.width;
let pageH = window.innerHeight;
let pageW = window.innerWidth;
let isWider = (window.innerWidth / window.innerHeight) >= (appConfig.screen.width / appConfig.screen.height);
console.log(isWider);
if (isWider) {
_el.style.height = window.innerHeight+'px';// '100%';
_el.style.width = pageH * appConfig.screen.width / appConfig.screen.height + 'px';
_el.style.top='0px';
_el.style.left=(window.innerWidth -pageH * appConfig.screen.width / appConfig.screen.height)*0.5+'px';
console.log(_el.style.width + "," + _el.style.height)
}
else {
_el.style.width = window.innerWidth+'px';// '100%';
_el.style.height = pageW * appConfig.screen.height / appConfig.screen.width + 'px';
_el.style.top= 0.5*(window.innerHeight-pageW * appConfig.screen.height / appConfig.screen.width)+'px';
_el.style.left='0px';
console.log(_el.style.height);
console.log(_el.style.top);
}
document.documentElement.style.fontSize = (_el.clientWidth / appConfig.screen.scale) + 'px';
}
var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
window.addEventListener(resizeEvt, init, false);
document.documentElement.addEventListener('DOMContentLoaded', init, false);
init()
}
3 使用方式
main.js 引入
import appConfig from './config/base.js';
Vue.prototype.appConfig=appConfig;
app.Vue 在mounted函数引入
import {pageResize} from './utils/resetScreenSize'
export default {
name: 'App',
data(){
return{
}
},
mounted(){
pageResize();
console.log('pageResize');
}
}
组件中样式 lang="stylus"
.mc{
display :flex;
flex-direction :column;
align-content :center;
justify-content :center;
display: flex;
flex: 1 1 auto;
flex-direction: column;
padding:(15/96)rem;
}
.leftC{
width :(410/96)rem;
}
.centerC{
width :(1060/96)rem;
}
.rightC{
width :(450/96)rem;
}
其中 96为 配置文件中1920/20得来,这样不用在进行各种换算了
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
javascript的new关键字用法是什么?关于new关键字,大家应该都比较熟悉,这篇文章主要给大家分享构造函数、new操作符和如何实现一个new,小编觉得挺实用的,感兴趣的朋友就继续往下看吧。
这篇文章我们来了解用jQuery怎样清空ul里的内容,这里使用到“$(ul元素)”语句和html()方法,实现过程和代码如下,有需要的朋友可以参考,接下来就跟随小编来一起学习一下吧!
浅谈访问vue实例this指针的相关知识,一些朋友可能会遇到这方面的问题,对此在下文小编向大家来讲解一下,内容详细,易于理解,希望大家阅读完这篇能有收获哦,有需要的朋友就往下看吧!
JavaScript即将推出两个新的数据类型:Record 和 Tuple ,这俩是啥呢?其实就是一个只读的 Object 和 Array,其实在其它语言中已经有类似的数据类型了,例如 Python 中也有 Tuple(元祖)这一类型,作用也是一个只读的数组(在Python里叫只读的列表),一起来了解一下,这个特性是一个第2阶段提案(即差不多稳了),想要提前体验的,文末也有 polyfill 的使用教程!
这篇文章主要介绍了vue-router钩子函数实现路由守卫,对vue感兴趣的同学,可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 ICP核准(ICP备案)粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008