在計算手機端頁面的時候, 使用rem和less的方式, 能夠方便的設置須要的大小等css
在head中添加html
<script> (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (!clientWidth) return; if(clientWidth>=750){ docEl.style.fontSize = '100px'; }else{ docEl.style.fontSize = 100 * (clientWidth / 750) + 'px'; } }; if (!doc.addEventListener) return; win.addEventListener(resizeEvt, recalc, false); doc.addEventListener('DOMContentLoaded', recalc, false); })(document, window); </script>
cnpm install --save-dev less less-loader
{ test: /\.less$/, use: [ "style-loader", "css-loader", "less-loader" ] }
cnpm install --save-dev style-loader css-loader
<style scoped lang="less"> </style>
<template> <div class="hello"> <div class="box"> <p> 哈哈 </p> </div> </div> </template> <script> export default { name: 'HelloWorld', data () { return { msg: 'Welcome to Your Vue.js App' } } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped lang="less"> /*200 * 300 寬度*/ .box{ width: 200 / 50rem; height: 300 / 50rem; background: dodgerblue; font-size: 16 / 50rem; } </style>