Vue移动端的适配
2018-03-05 18:58
531 查看
Vue移动端的适配
一、通过原生js设置html的font-size属性
1. 创建公共js文件(global.js)function setHtmlFontSize() {
const screenWidth = document.documentElement.clientWidth || document.body.clientWidth;
document.getElementsByTagName('html')[0].style.fontSize = screenWidth*2/10+'px';
}
//事件监听触发
function setFontSize() {
window.onresize = function () {
setHtmlFontSize();
}
}
//将方法暴露
module.exports = {
setFontSize,
setHtmlFontSize
}2. 在App.vue组件(App.vue)//引入js
import {setFontSize, setHtmlFontSize} from './assets/js/global';
export default {
name: 'app',
computed: mapGetters(['loading','shownav']),//使用对象展开运算符将 getter 混入 computed 对象中,其中loading和shownav属性
//监听路由的变化
watch:{
//$route路由信息对象
$route(to,from){
}
},
components:{
//组件
},
mounted(){//生命周期钩子:el被新创建的vm.$el替换,并挂载到实例上去之后调用该钩子
setHtmlFontSize();
setFontSize();
}
}
二、通过lib-flexible插件
1. 安装lib-flexble插件npm install lib-flexible --save2. 在项目的入口文件main.js引入lib-flexible
一、通过原生js设置html的font-size属性
1. 创建公共js文件(global.js)function setHtmlFontSize() {
const screenWidth = document.documentElement.clientWidth || document.body.clientWidth;
document.getElementsByTagName('html')[0].style.fontSize = screenWidth*2/10+'px';
}
//事件监听触发
function setFontSize() {
window.onresize = function () {
setHtmlFontSize();
}
}
//将方法暴露
module.exports = {
setFontSize,
setHtmlFontSize
}2. 在App.vue组件(App.vue)//引入js
import {setFontSize, setHtmlFontSize} from './assets/js/global';
export default {
name: 'app',
computed: mapGetters(['loading','shownav']),//使用对象展开运算符将 getter 混入 computed 对象中,其中loading和shownav属性
//监听路由的变化
watch:{
//$route路由信息对象
$route(to,from){
}
},
components:{
//组件
},
mounted(){//生命周期钩子:el被新创建的vm.$el替换,并挂载到实例上去之后调用该钩子
setHtmlFontSize();
setFontSize();
}
}
二、通过lib-flexible插件
1. 安装lib-flexble插件npm install lib-flexible --save2. 在项目的入口文件main.js引入lib-flexible
相关文章推荐
- Vue:将px转化为rem,适配移动端
- Vue-cli 将px转化为rem,适配移动端
- Vue:将px转化为rem,适配移动端
- vuejs第二篇 vue-cli配置移动端自适配(引入flexible)
- vue做移动端适配最佳解决方案(亲测有效)
- 详解vue移动端项目的适配(以mint-ui为例)
- vue 移动端屏幕适配 使用rem
- vue使用rem实现 移动端屏幕适配
- vue项目中使用lib-flexible解决移动端适配的问题解决
- [置顶] 解决vue移动端项目嵌入优酷视频问题
- 移动端高清、多屏适配方案
- 移动端页面开发适配 rem布局原理
- 前端移动端适配总结
- Html5 移动端适配
- 移动端之vue基础学习
- vue移动端裁剪图片结合插件Cropper的使用实例代码
- wc-swiper:基于 Vue 实现的 移动端图片轮播组件
- 移动端适配问题
- vue 和vue-touch 实现移动端左右导航效果(仿京东移动站导航)
- 移动端之js控制rem,适配字体