px vue in turn rem, for mobile terminal
1. Download the lib-flexible
I use a vue-cli + webpack, it is by npm install the
npm i lib-flexible --save
2. Introduction lib-flexible
incorporated lib-flexible in the main.js
import 'lib-flexible/flexible'
3. Set meta tags
by meta tags, width, and scaling the device is provided
<meta name="viewport" content="width=device-width, initial-scale=1.0">
4. Installation px2rem-loader
npm install px2rem-loader
5. Configure px2rem-loader
here is an important step ~~
Util.js found in the build file, add px2rem-loader to cssLoaders in, such as:
const cssLoader = {
loader: 'css-loader',
options: {
minimize: process.env.NODE_ENV === 'production',
sourceMap: options.sourceMap
}
}
const px2remLoader = {
loader: 'px2rem-loader',
options: {
remUnit: 75
}
}
At the same time, add px2remLoader in generateLoaders method
function generateLoaders (loader, loaderOptions) {
const loaders = [cssLoader,px2remLoader]
if (loader) {
loaders.push({
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap
})
})
}
6. Restart, everything ok ~
When you finish configuring, you only need to restart the next service, it is automatically converted into a rem
npm run dev