效果

#mermaid-svg-O0n9N0Pq5xuLBK3e .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .label text{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .node rect,#mermaid-svg-O0n9N0Pq5xuLBK3e .node circle,#mermaid-svg-O0n9N0Pq5xuLBK3e .node ellipse,#mermaid-svg-O0n9N0Pq5xuLBK3e .node polygon,#mermaid-svg-O0n9N0Pq5xuLBK3e .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-O0n9N0Pq5xuLBK3e .node .label{text-align:center;fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .node.clickable{cursor:pointer}#mermaid-svg-O0n9N0Pq5xuLBK3e .arrowheadPath{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-O0n9N0Pq5xuLBK3e .flowchart-link{stroke:#333;fill:none}#mermaid-svg-O0n9N0Pq5xuLBK3e .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-O0n9N0Pq5xuLBK3e .edgeLabel rect{opacity:0.9}#mermaid-svg-O0n9N0Pq5xuLBK3e .edgeLabel span{color:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-O0n9N0Pq5xuLBK3e .cluster text{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-O0n9N0Pq5xuLBK3e .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-O0n9N0Pq5xuLBK3e text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-O0n9N0Pq5xuLBK3e .actor-line{stroke:grey}#mermaid-svg-O0n9N0Pq5xuLBK3e .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .sequenceNumber{fill:#fff}#mermaid-svg-O0n9N0Pq5xuLBK3e #sequencenumber{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e #crosshead path{fill:#333;stroke:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .messageText{fill:#333;stroke:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-O0n9N0Pq5xuLBK3e .labelText,#mermaid-svg-O0n9N0Pq5xuLBK3e .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-O0n9N0Pq5xuLBK3e .loopText,#mermaid-svg-O0n9N0Pq5xuLBK3e .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-O0n9N0Pq5xuLBK3e .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-O0n9N0Pq5xuLBK3e .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-O0n9N0Pq5xuLBK3e .noteText,#mermaid-svg-O0n9N0Pq5xuLBK3e .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-O0n9N0Pq5xuLBK3e .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-O0n9N0Pq5xuLBK3e .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-O0n9N0Pq5xuLBK3e .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-O0n9N0Pq5xuLBK3e .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .section{stroke:none;opacity:0.2}#mermaid-svg-O0n9N0Pq5xuLBK3e .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-O0n9N0Pq5xuLBK3e .section2{fill:#fff400}#mermaid-svg-O0n9N0Pq5xuLBK3e .section1,#mermaid-svg-O0n9N0Pq5xuLBK3e .section3{fill:#fff;opacity:0.2}#mermaid-svg-O0n9N0Pq5xuLBK3e .sectionTitle0{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .sectionTitle1{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .sectionTitle2{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .sectionTitle3{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-O0n9N0Pq5xuLBK3e .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .grid path{stroke-width:0}#mermaid-svg-O0n9N0Pq5xuLBK3e .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-O0n9N0Pq5xuLBK3e .task{stroke-width:2}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskText:not([font-size]){font-size:11px}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-O0n9N0Pq5xuLBK3e .task.clickable{cursor:pointer}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskText0,#mermaid-svg-O0n9N0Pq5xuLBK3e .taskText1,#mermaid-svg-O0n9N0Pq5xuLBK3e .taskText2,#mermaid-svg-O0n9N0Pq5xuLBK3e .taskText3{fill:#fff}#mermaid-svg-O0n9N0Pq5xuLBK3e .task0,#mermaid-svg-O0n9N0Pq5xuLBK3e .task1,#mermaid-svg-O0n9N0Pq5xuLBK3e .task2,#mermaid-svg-O0n9N0Pq5xuLBK3e .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutside0,#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutside2{fill:#000}#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutside1,#mermaid-svg-O0n9N0Pq5xuLBK3e .taskTextOutside3{fill:#000}#mermaid-svg-O0n9N0Pq5xuLBK3e .active0,#mermaid-svg-O0n9N0Pq5xuLBK3e .active1,#mermaid-svg-O0n9N0Pq5xuLBK3e .active2,#mermaid-svg-O0n9N0Pq5xuLBK3e .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-O0n9N0Pq5xuLBK3e .activeText0,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeText1,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeText2,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeText3{fill:#000 !important}#mermaid-svg-O0n9N0Pq5xuLBK3e .done0,#mermaid-svg-O0n9N0Pq5xuLBK3e .done1,#mermaid-svg-O0n9N0Pq5xuLBK3e .done2,#mermaid-svg-O0n9N0Pq5xuLBK3e .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-O0n9N0Pq5xuLBK3e .doneText0,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneText1,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneText2,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneText3{fill:#000 !important}#mermaid-svg-O0n9N0Pq5xuLBK3e .crit0,#mermaid-svg-O0n9N0Pq5xuLBK3e .crit1,#mermaid-svg-O0n9N0Pq5xuLBK3e .crit2,#mermaid-svg-O0n9N0Pq5xuLBK3e .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCrit0,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCrit1,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCrit2,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCrit0,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCrit1,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCrit2,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-O0n9N0Pq5xuLBK3e .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-O0n9N0Pq5xuLBK3e .milestoneText{font-style:italic}#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCritText0,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCritText1,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCritText2,#mermaid-svg-O0n9N0Pq5xuLBK3e .doneCritText3{fill:#000 !important}#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCritText0,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCritText1,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCritText2,#mermaid-svg-O0n9N0Pq5xuLBK3e .activeCritText3{fill:#000 !important}#mermaid-svg-O0n9N0Pq5xuLBK3e .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-O0n9N0Pq5xuLBK3e g.classGroup text .title{font-weight:bolder}#mermaid-svg-O0n9N0Pq5xuLBK3e g.clickable{cursor:pointer}#mermaid-svg-O0n9N0Pq5xuLBK3e g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-O0n9N0Pq5xuLBK3e g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-O0n9N0Pq5xuLBK3e .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-O0n9N0Pq5xuLBK3e .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-O0n9N0Pq5xuLBK3e .dashed-line{stroke-dasharray:3}#mermaid-svg-O0n9N0Pq5xuLBK3e #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e .commit-id,#mermaid-svg-O0n9N0Pq5xuLBK3e .commit-msg,#mermaid-svg-O0n9N0Pq5xuLBK3e .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-O0n9N0Pq5xuLBK3e g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-O0n9N0Pq5xuLBK3e g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-O0n9N0Pq5xuLBK3e g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-O0n9N0Pq5xuLBK3e .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-O0n9N0Pq5xuLBK3e .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-O0n9N0Pq5xuLBK3e .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-O0n9N0Pq5xuLBK3e .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-O0n9N0Pq5xuLBK3e .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-O0n9N0Pq5xuLBK3e .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-O0n9N0Pq5xuLBK3e .edgeLabel text{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-O0n9N0Pq5xuLBK3e .node circle.state-start{fill:black;stroke:black}#mermaid-svg-O0n9N0Pq5xuLBK3e .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-O0n9N0Pq5xuLBK3e #statediagram-barbEnd{fill:#9370db}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-state .divider{stroke:#9370db}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-O0n9N0Pq5xuLBK3e .note-edge{stroke-dasharray:5}#mermaid-svg-O0n9N0Pq5xuLBK3e .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-O0n9N0Pq5xuLBK3e .error-icon{fill:#522}#mermaid-svg-O0n9N0Pq5xuLBK3e .error-text{fill:#522;stroke:#522}#mermaid-svg-O0n9N0Pq5xuLBK3e .edge-thickness-normal{stroke-width:2px}#mermaid-svg-O0n9N0Pq5xuLBK3e .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-O0n9N0Pq5xuLBK3e .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-O0n9N0Pq5xuLBK3e .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-O0n9N0Pq5xuLBK3e .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-O0n9N0Pq5xuLBK3e .marker{fill:#333}#mermaid-svg-O0n9N0Pq5xuLBK3e .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-O0n9N0Pq5xuLBK3e {color: rgba(0, 0, 0, 0.75);font: ;}

A
B
C

一、npm安装依赖

项目基础配置使用 vue-cli 生成
自适应方案核心: 阿里可伸缩布局方案 lib-flexible
px转rem:px2rem,它有webpack的loader px2rem

npm i lib-flexible -S
npm i px2rem-loader -D

二、在vue.config.js配置,这里我是按照1920*1080缩放

  css: {loaderOptions: {postcss: {plugins: [require('postcss-px2rem')({remUnit: 192})]}},},

三、引入flexible

//main.js
import 'lib-flexible'
  • 到这里自适应已经生效了
  • 这里还有一个问题,就是屏幕宽度大于540的时候,把屏幕宽度写死成540了
  • 找到路径\node_modules\lib-flexible\flexible.js

  • 修改成
    if (width / dpr > 540) { width = width * dpr; }

三、因为上边的修改,每次装依赖,都需要改动,这里提取出来就好:在utils目录下新建flexible.js文件

  • 把文件放在utils 下引入即可
//flexible.js
;(function(win, lib) {var doc = win.document;var docEl = doc.documentElement;var metaEl = doc.querySelector('meta[name="viewport"]');var flexibleEl = doc.querySelector('meta[name="flexible"]');var dpr = 0;var scale = 0;var tid;var flexible = lib.flexible || (lib.flexible = {});if (metaEl) {console.warn('将根据已有的meta标签来设置缩放比例');var match = metaEl.getAttribute('content').match(/initial\-scale=([\d\.]+)/);if (match) {scale = parseFloat(match[1]);dpr = parseInt(1 / scale);}} else if (flexibleEl) {var content = flexibleEl.getAttribute('content');if (content) {var initialDpr = content.match(/initial\-dpr=([\d\.]+)/);var maximumDpr = content.match(/maximum\-dpr=([\d\.]+)/);if (initialDpr) {dpr = parseFloat(initialDpr[1]);scale = parseFloat((1 / dpr).toFixed(2));}if (maximumDpr) {dpr = parseFloat(maximumDpr[1]);scale = parseFloat((1 / dpr).toFixed(2));}}}if (!dpr && !scale) {var isAndroid = win.navigator.appVersion.match(/android/gi);var isIPhone = win.navigator.appVersion.match(/iphone/gi);var devicePixelRatio = win.devicePixelRatio;if (isIPhone) {// iOS下,对于2和3的屏,用2倍的方案,其余的用1倍方案if (devicePixelRatio >= 3 && (!dpr || dpr >= 3)) {dpr = 3;} else if (devicePixelRatio >= 2 && (!dpr || dpr >= 2)){dpr = 2;} else {dpr = 1;}} else {// 其他设备下,仍旧使用1倍的方案dpr = 1;}scale = 1 / dpr;}docEl.setAttribute('data-dpr', dpr);if (!metaEl) {metaEl = doc.createElement('meta');metaEl.setAttribute('name', 'viewport');metaEl.setAttribute('content', 'initial-scale=' + scale + ', maximum-scale=' + scale + ', minimum-scale=' + scale + ', user-scalable=no');if (docEl.firstElementChild) {docEl.firstElementChild.appendChild(metaEl);} else {var wrap = doc.createElement('div');wrap.appendChild(metaEl);doc.write(wrap.innerHTML);}}function refreshRem(){var width = docEl.getBoundingClientRect().width;if (width / dpr > 540) {width = width * dpr;}var rem = width / 10;docEl.style.fontSize = rem + 'px';flexible.rem = win.rem = rem;}win.addEventListener('resize', function() {clearTimeout(tid);tid = setTimeout(refreshRem, 300);}, false);win.addEventListener('pageshow', function(e) {if (e.persisted) {clearTimeout(tid);tid = setTimeout(refreshRem, 300);}}, false);if (doc.readyState === 'complete') {doc.body.style.fontSize = 12 * dpr + 'px';} else {doc.addEventListener('DOMContentLoaded', function(e) {doc.body.style.fontSize = 12 * dpr + 'px';}, false);}refreshRem();flexible.dpr = win.dpr = dpr;flexible.refreshRem = refreshRem;flexible.rem2px = function(d) {var val = parseFloat(d) * this.rem;if (typeof d === 'string' && d.match(/rem$/)) {val += 'px';}return val;}flexible.px2rem = function(d) {var val = parseFloat(d) / this.rem;if (typeof d === 'string' && d.match(/px$/)) {val += 'rem';}return val;}})(window, window['lib'] || (window['lib'] = {}));

三、在项目的入口文件 main.js 里引入 lib-flexible

//main.js
//屏幕分辨率适配
import './utils/lib-flexible/flexible'

到这里就可以用了
按需求写代码就可以,这里需注意:尽量别写行内样式,行内元素无法转换为rem

vue项目PC端屏幕分辨率与窗口大小自适应相关推荐

  1. vue适配PC端屏幕自适应

    vue适配PC端屏幕自适应 1.下载postcss-px2rem和px2rem-loader npm i postcss-px2rem px2rem-loader 2.src目录下新建utils文件夹 ...

  2. vue PC端屏幕分辨率自适应

    场景 不同的电脑屏幕大小根据宽度进行等比缩放,自适应.代码中的单位还是使用px,根据设计稿的尺寸来进行还原.它会自动转为rem. 第一步 安装依赖 npm install postcss-px2rem ...

  3. Vue项目pc端适配方案(scss)

    前言:vue项目适配可借助于插件lib-flexible 和postcss-px2rem. lib-flexible插件的作用:根据屏幕尺寸不同设置html根标签的字体大小,1rem即等于根标签的字体 ...

  4. vue项目pc端使用rem进行适配 (lib-flexible+postcss-pxtorem)

    1.使用vue-cli创建项目 vue create my-app 2.安装lib-flexible与postcss-pxtorem依赖 npm install lib-flexible -Snpm ...

  5. vue的PC端和移动端分辨率适配

    使用lib-flexible和px2rem实现移动端和PC端界面适配 注释:lib-flexbles是由阿里团队很早提出解决屏幕分辨率适配的问题.现已不被推荐(因为目前比较主流的适配方案是使用vw和v ...

  6. 基于 Vue JS、Element UI、Nuxt JS的项目PC端前端手册

    基于 Vue JS.Element UI.Nuxt JS的项目PC端前端手册 前言:笔记写于2020年5月左右,刚开始做前端时整理的笔记 1.环境搭建 1.安装nodeJs ​ 官网下载地址:http ...

  7. vue的pc端适配vw vh rem

    安装命令: npm i postcss-px-to-viewport@1.1.1npm i postcss-pxtorem@5.1.1 2.安装完之后在根目录新建postcss.config.js(和 ...

  8. 【移动端网页布局】移动端网页布局基础概念 ① ( 移动端浏览器 | 移动端屏幕分辨率 | 移动端网页调试方法 )

    文章目录 一.移动端浏览器 二.移动端屏幕分辨率 三.移动端网页调试方法 一.移动端浏览器 移动端浏览器 比 PC 端浏览器发展要晚 , 使用的技术比较新 , 对 HTML5 + CSS3 支持较好 ...

  9. pc端不同分辨率适配

    1.以1920* 1080的设计稿为例,实现PC端不同分辨率适配 2.安装依赖 npm install --save lib-flexible     或者  yarn add lib-flexibl ...

最新文章

  1. 如何使用Log4j?
  2. 抗击疫情!阿里云为加速新药疫苗研发提供免费AI算力
  3. 自回归解码加速64倍,谷歌提出图像合成新模型MaskGIT
  4. 十三条道德准则-富兰克林
  5. LeetCode 141. 环形链表 简单难度
  6. php如何连接mongodb,PHP 连接 MongoDB
  7. Python 脚本错误:IndentationError: unindent does not match any outer indentation level
  8. java中英对比_2017-11-09 中英文代码对比系列之Java一例
  9. 吊打面试官!Redis 常见面试题请收好 | 原力计划
  10. C++ Member Functions的各种调用方式
  11. Android Studio 2.2 正式稳定版已发布,先睹为快!
  12. 学习笔记——矩阵键盘的扫描原理与基本应用
  13. 【GNSS】GREAT多频多系统GREAT-UPD开源代码-第三章 中间及结果文件格式
  14. 从单一服务到多元化服务,智能机器人JIMI的架构改造及逐步开放的过程
  15. 案例|山东省中医院基于ZABBIX构建网络设备监控预警平台
  16. OpenMMLab 实战营打卡 - 第 四 课 目标检测算法基础
  17. POJ 3009 Curling 2.0 {深度优先搜索}
  18. 比较器翻转抖动原因及对策
  19. 【68测试20161117】【数论】【乱搞】【前缀和】
  20. 历年数学建模特等优秀论文汇总

热门文章

  1. 如何考虑SEO优化?
  2. nginx修改响应头(可屏蔽后端服务器的信息:IIS,PHP等)
  3. 【web前端开发教程】
  4. 由某梦CMS导致近来改版的太多数据库大挪移手软了
  5. 不要告诉我你不知道这32个网站!
  6. 汇编语言中xor指令_XOR寄存器,寄存器(汇编程序)
  7. 动态修改窗口标题和类名
  8. 前端搜索引擎优化SEO优化之Title 和 Meta 标签
  9. 【实验报告】微处理器原理与应用 CPUHomework1.2 上篇【掌握DEBUG基本命令及其功能 查看CPU和内存 用机器指令和汇编指令编程】
  10. html中怎么给地图添加标记,百度地图中怎么添加旗帜标记?