安装完vant和post-css-to-viewport,根目录新建postcss.config.js
const path = require('path'); module.exports = ({ file }) => { const designWidth = file.dirname.includes("vant") ? 375 : 750; return { plugins: { autoprefixer: {}, "postcss-px-to-viewport": { unitToConvert: "px", viewportWidth: designWidth, unitPrecision: 6, propList: ["*"], viewportUnit: "vw", fontViewportUnit: "vw", selectorBlackList: [], minPixelValue: 1, mediaQuery: true, exclude: [], landscape: false } } } }