国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

vue移動(dòng)端屏幕適配詳解

2024-05-06 15:39:58
字體:
供稿:網(wǎng)友

flexible

vue移動(dòng)端屏幕適配,查看項(xiàng)目地址

效果預(yù)覽

# 項(xiàng)目clone
git clone git@github.com:NicolasGui/flexible.git

# 進(jìn)入項(xiàng)目目錄
cd flexible

# 安裝依賴
npm install

# 啟動(dòng)服務(wù) localhost:8080
npm run dev

原理概述

插件安裝

# 插件一:amfe-flexible
npm install amfe-flexible --save
#  插件二: node-sass
npm install amfe-flexible --save  # 同時(shí),在main.js文件內(nèi)引入
npm install sass-loader --save

編寫js處理方法

在utils目錄下創(chuàng)建flex.js文件,內(nèi)容如下:

import Vue from 'vue'Vue.prototype.$setTitle = function (text) { document.title = text}Vue.prototype.$getPX = function (design, designWidth = 750) { // 750為設(shè)計(jì)稿寬度 // 獲取窗口尺寸 let width = document.documentElement.getBoundingClientRect().width // 計(jì)算縮放比例 let scale = width / designWidth // 獲取實(shí)時(shí)尺寸 return design * scale}

同時(shí),在main.js文件內(nèi)引入該js文件

import Vue from 'vue'import App from './App'import router from './router'import 'amfe-flexible'import './utils/flex'Vue.config.productionTip = falsenew Vue({ el: '#app', router, components: { App }, template: '<App/>'})

編寫css處理方法

在src目錄創(chuàng)建styles目錄,同時(shí)在該目錄新增common.scss文件,內(nèi)容如下:

body,div,ul,ol,dl,li,dt,dd,h1,h2,h3,h4,p,form,iframe,input,textarea,a,span,em,strong,img,html,nav,header,article,button,footer,var { padding:0; margin:0;}body { font:12px/1.2rem "Microsoft YaHei",tahoma,arial,sans-serif;min-width:320px;position:relative; }form,input {background:none;border:none;}ul,dl,ol {list-style-type:none;}h1, h2, h3, h4, h5 { font:12px/1.2rem "Microsoft YaHei",arial,tahoma; }a { text-decoration:none; }a:hover,a:focus { outline:none; }table { border-collapse:collapse;border-spacing:0; }img { border:none; }strong,b { font-weight:normal; }em,i,var { font-style:normal; }p { text-indent:0; }.clear { clear:both;height:0;line-height:0;overflow:hidden;width:0; }.clearfix:after { clear:both;content:".";display:block;font-size:0;height:0;visibility:hidden; } // 尺寸轉(zhuǎn)換 @function px2rem($px, $base-font-size: 75px) { /*設(shè)計(jì)稿寬度為750,因此此處為75*/ @if (unitless($px)) {  @return px2rem($px + 0px);  } @else if (unit($px) == rem) {  @return $px; } @return ($px / $base-font-size) * 1rem; } // 字體轉(zhuǎn)換 @mixin font-dpr($font-size) { font-size: $font-size; [data-dpr="2"] & {  font-size: $font-size * 2; } [data-dpr="3"] & {  font-size: $font-size * 3; } }

css內(nèi)使用

<style scoped lang='scss'> @import '../styles/common.scss'; .content{  width:px2rem(750); /*750為設(shè)計(jì)稿實(shí)際尺寸*/  font-size:px2rem(20) /*20為設(shè)計(jì)稿實(shí)際尺寸*/</style>            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 泰兴市| 神农架林区| 松阳县| 灵台县| 朝阳县| 齐河县| 福泉市| 汉寿县| 扬中市| 云梦县| 西安市| 沅陵县| 前郭尔| 洮南市| 江津市| 巨鹿县| 都安| 宁安市| 文登市| 浠水县| 连城县| 漳浦县| 聊城市| 恭城| 大悟县| 齐齐哈尔市| 泾阳县| 南川市| 衡水市| 竹北市| 弥渡县| 肥城市| 普兰县| 东阳市| 平塘县| 剑河县| 高陵县| 梁山县| 克什克腾旗| 东莞市| 修武县|