#適配
//lib-flexible修改根字體大小
//autoprefixer可以自動(dòng)在樣式中添加瀏覽器廠商前綴,避免手動(dòng)處理樣式兼容問(wèn)題
npm install postcss-plugin-px2rem autoprefixer@8.0.0
npm i lib-flexible --save
//npm i autoprefixer@8.0.0 //解決版本過(guò)高的問(wèn)題
#public-index.html
<meta name="viewport" content="width=device-width,initial-scale=1.0">//注釋掉
#main.js
import 'lib-flexible/flexible.js'
新建postcss.config.js
const AutoPrefixer = require('autoprefixer')
const pxtorem = require('postcss-plugin-px2rem')
module.exports = ({ file }) => {
let remUnit
if (file && file.dirname && file.dirname.indexOf('vant') > -1) {
remUnit = 37.5
} else {
remUnit = 75
}
return {
plugins: [
AutoPrefixer({
browsers: ['last 20 versions', 'android >= 4.0']
}),
pxtorem({
rootValue: remUnit,
propList: ['*'],
selectorBlackList: ['van-circle__layer']
})
]
}
}
#新建vue.config.js
module.exports = {
devServer: {
disableHostCheck: true,
// 設(shè)置代理
proxy: {
"/api": {
target: "http://192.168.xxx.xxx", // 域名
ws: true, // 是否啟用websockets
changeOrigin: true, //開(kāi)啟代理:在本地會(huì)創(chuàng)建一個(gè)虛擬服務(wù)端,然后發(fā)送請(qǐng)求的數(shù)據(jù),并同時(shí)接收請(qǐng)求的數(shù)據(jù),這樣服務(wù)端和服務(wù)端進(jìn)行數(shù)據(jù)的交互就不會(huì)有跨域問(wèn)題
pathRewrite: {
"^/api": "/"
}
}
}
},
lintOnSave: true
}
#https://vant-contrib.gitee.io/vant/#/zh-CN/quickstart
npm i vant -S
# 安裝插件
npm i babel-plugin-import -D
//新建 .babelrc 配置按需引入
{
"plugins": [
[
"import",
{
"libraryName": "vant",
"libraryDirectory": "es",
"style": true
}
]
]
}
#vant使用模板
<template>
<div>
<van-button type="default">默認(rèn)按鈕</van-button>
<van-button type="primary">主要按鈕</van-button>
</div>
</template>
<script>
import { Button } from "vant";
export default {
name: "Home",
components:{
[Button.name]:Button
}
};
</script>
vue+vant 移動(dòng)端項(xiàng)目(安裝vant+rem適配)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- Vant UI + Vue + Cli3.0 + Rem移動(dòng)端項(xiàng)目搭建 1. 創(chuàng)建vue項(xiàng)目 創(chuàng)建項(xiàng)目 引入les...
- 1.下載lib-flexible 使用的是vue-cli+webpack,通過(guò)npm來(lái)安裝的 2.引入lib-fl...
- 1.下載lib-flexible使用的是vue-cli+webpack,通過(guò)npm來(lái)安裝的 2.引入lib-fle...
- vue-cli 3.0+vant項(xiàng)目使用postcss-pxtorem和amfe-flexible 進(jìn)行移動(dòng)端適配...
- vue-cli 3.0+vant項(xiàng)目使用postcss-pxtorem和amfe-flexible 進(jìn)行移動(dòng)端適配...