惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
量子位
G
Google Developers Blog
J
Java Code Geeks
N
Netflix TechBlog - Medium
博客园 - 聂微东
宝玉的分享
宝玉的分享
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
爱范儿
爱范儿
雷峰网
雷峰网
M
MIT News - Artificial intelligence
T
Tailwind CSS Blog
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss

博客园 - MvloveYouForever

添加gitignore mac安装小龙虾 flutter重新学习 添加ssh后,ssh-rsa fatal: Could not read git合并提交 cordova打印插件备注 H5开发类似rpx实现方法 maven仓库地址 idea与其他软件激活办法 linux常用命令总结 Command line is too long mysql安装教程备份 mybatis-plus 条件参数说明 关于打包electron应用 关于spring unicloud短信不能用 关于mybatis 关于maven vue2 和 vue3的区别 父子组件v-modle,vue2和vue3的区别 Vue3知识点
uniapp简单移动端H5电脑端适配方案
MvloveYouForever · 2025-01-04 · via 博客园 - MvloveYouForever

1、创建pc.js

// #ifdef H5
(function () {
  var u = navigator.userAgent,
    w = window.innerWidth;
  if (!u.match(/AppleWebKit.*Mobile.*/) || u.indexOf("iPad") > -1) {
    window.innerWidth = 750 * (w / 1920);
    window.onload = function () {
      window.innerWidth = w;
    };
  }
})();
// #endif

2、App.vue添加适配样式

<style lang="scss">
/*  #ifdef  H5  */
body {
  max-width: 828rpx;  //最大宽度自己可以调整
  margin: auto !important;
}
/*  #endif  */
</style>

3、main.js中引入pc.js(要在导入app示例之前引入)

import Vue from "vue";
//导入PC适配JS(H5)
// #ifdef H5
import "./common/services/pc";
// #endif
import App from "./App";