目前感覺沒有特別完美的解決方法
1.首先新建一個(gè)功能js文件fongbase.js
export default {
created() {
const self = this;
},
mounted() {
const self = this;
},
methods: {
//設(shè)置字體
getRootFontSize(){
const self = this;
var fontSize = getApp().globalData.rootFontSize;
if(fontSize){
return fontSize;
}else{
fontSize = uni.getStorageSync('root_font_size');
if(fontSize){
getApp().globalData.rootFontSize=fontSize;
}else{
fontSize='12px';//默認(rèn)字體大小
self.setRootFontSize(fontSize);
}
return fontSize;
}
},
setRootFontSize(fontSize){
uni.setStorageSync('root_font_size',fontSize);
getApp().globalData.rootFontSize=fontSize;
},
}
}
2.新建一個(gè)用戶控制大小的界面,這里用的是uniapp的滑塊組件文章來源:http://www.zghlxwxcb.cn/news/detail-512063.html
<template>
<page-meta :root-font-size="getRootFontSize()"></page-meta>
<view class="content">
<view class=""><view class="" style="font-size: 1rem;">文字大小</view></view>
<view class="" style="width:100%;padding: 0 20rpx;">
<slider
style="width: 100%;"
min="12"
max="16"
:value="fontValue"
@change="sliderChange"
show-value
step="2"
/>
</view>
<u-button type="primary" @click="submit">確定</u-button>
</view>
</template>
<script>
import fontbase from '@/utils/fontbase.js';
export default {
extends: fontbase,
data() {
return {
fontValue: 12
};
},
onLoad() {},
onShow() {
let a = this.getRootFontSize();
let aa = a.substring(0, 2);
this.fontValue = Number(aa);
},
methods: {
submit() {
uni.reLaunch({
url:'/pages/v2-dealers/my/index'
})
console.log('submit');
},
sliderChange(e) {
console.log('value 發(fā)生變化:' + e.detail.value);
const self = this;
let nowFontSize = e.detail.value + 'px';
console.log(nowFontSize);
self.fontEnd = nowFontSize;
console.log(nowFontSize);
self.setRootFontSize(nowFontSize);
}
}
};
</script>
<style>
.fontchange {
font-size: 1rem;
}
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
padding: 5px;
box-sizing: border-box;
}
.logo {
width: 100%;
/* height: auto; */
margin-top: 10px;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
3.在想要修改的頁面加代碼塊內(nèi)容,麻煩的就是需要一個(gè)個(gè)頁面去添加,然后改單位,我的理解是page-mate的根字節(jié)大小改為了14px,那么單位要改為rem,1rem=14px,所以說這個(gè)字體大小感覺不是很精確文章來源地址http://www.zghlxwxcb.cn/news/detail-512063.html
<page-meta :root-font-size="getRootFontSize()"></page-meta>
import fontbase from '@/utils/fontbase.js'
export default {
extends:fontbase,
.fontchange{
font-size: 1rem;
}
到了這里,關(guān)于uniapp用戶設(shè)置字體大小的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!