亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

用vue-cli3搭建了一個項目,引入了一個rem.js文件,但是編譯報錯

用vue-cli3搭建了一個項目,引入了一個rem.js文件,但是編譯報錯

四季花海 2019-03-18 21:59:00
我把rem.js放在了assets目錄下,編譯之后報:Uncaught SyntaxError: Unexpected token <這個該怎么解決?
查看完整描述

2 回答

?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

這是有個地方少了 "<"這個 箭頭的錯誤,你檢查下引入的代碼

查看完整回答
反對 回復 2019-03-18
?
holdtom

TA貢獻1805條經驗 獲得超10個贊

rem 都已經工程化了。。。建議不要不要這么手動寫 。
a. 安裝這倆
"amfe-flexible": "^2.2.1"
"postcss-pxtorem": "^4.0.1"
b. postcss.config.js 配置(這是我的例子,使用的是vant。實際規則跟你自己使用的UI庫來決定是否轉換 以及轉換基準)

const autoprefixer = require('autoprefixer');const pxtorem = require('postcss-pxtorem');module.exports = ({ file }) => {    let ROOTValue;    if (file && file.dirname && (file.dirname.indexOf('vant') > -1) || file.dirname.indexOf('mpvue-calendar') > -1) {
        ROOTValue = 37.5
    } else {
        ROOTValue = 75
    }    return {
        plugins: [
            autoprefixer(),
            pxtorem({
              rootValue: ROOTValue,
              propList: ['*']
            })
        ]
    }
}

c. main.js 
import 'amfe-flexible';
d. 頁面里按照設計圖上的多少px就直接寫px,打包后自動轉成rem


查看完整回答
反對 回復 2019-03-18
  • 2 回答
  • 0 關注
  • 2493 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號