0%

父元素不定宽,利用line-height实现
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<style>
.box{
height: 400px;
background: red;
}
.content{
line-height: 400px; //设置和父元素的高度一样
text-align: center;
}
</style>
<div class="box">
<div class="content">
这是子元素子元素子元素这是子元素子元素子元素这是子元素子元素子元素这是子元素子元素子元素
</div>
</div>
阅读全文 »

使用 Location 对象提供的方法
1
window.location.reload()

==但是这种方法,有的小米手机不会刷新。==

使用vue路由提供给我们的方法
1
this.$router.go(0)

相对于当前页面向前或向后跳转多少个页面,类似 window.history.go(n)。n可为正数可为负数。正数返回上一个页面

阅读全文 »

翻转字符串
1
2
3
function reser(str){
return [...str].reverse().join('')
}
判断回文字符串
1
2
3
4
5
6
7
function  Mosl(str){
let stri = ''
for(let i= str.length; i>=0; i--){
stri+= str.charAt(i)
}
return str === stri
}
阅读全文 »

安装postcss-pxtorem插件
1
2
npm install postcss-pxtorem --save
cnpm install postcss-pxtorem --save
新建rem.js文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
const baseSize = 32
// 设置 rem 函数
function setRem () {
// 当前页面宽度相对于 750 宽的缩放比例,可根据自己需要修改。
const scale = document.documentElement.clientWidth / 750
// 设置页面根节点字体大小
document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px'
}
// 初始化
setRem()
// 改变窗口大小时重新设置 rem
window.onresize = function () {
setRem()
}
阅读全文 »