mirror of
https://github.com/sunniejs/vue-h5-template.git
synced 2025-10-06 03:09:59 +08:00
增加localstorage和rem
This commit is contained in:
parent
9d3fd87b05
commit
348f7867d7
13351
package-lock.json
generated
13351
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
src/utils/localstorage.js
Normal file
20
src/utils/localstorage.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* localStorage操作
|
||||||
|
* @type {{get(*=, *=): *, save(*=, *=): void, clear(): void, remove(*=): void}}
|
||||||
|
*/
|
||||||
|
const db = {
|
||||||
|
save(key, value) {
|
||||||
|
localStorage.setItem(key, JSON.stringify(value))
|
||||||
|
},
|
||||||
|
get(key, defaultValue = {}) {
|
||||||
|
return JSON.parse(localStorage.getItem(key)) || defaultValue
|
||||||
|
},
|
||||||
|
remove(key) {
|
||||||
|
localStorage.removeItem(key)
|
||||||
|
},
|
||||||
|
clear() {
|
||||||
|
localStorage.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default db
|
26
src/utils/rem.js
Normal file
26
src/utils/rem.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* 为了适配rem
|
||||||
|
* 可以在main.js中全局引入
|
||||||
|
*/
|
||||||
|
(function(window, document) {
|
||||||
|
function resize() {
|
||||||
|
var ww = window.innerWidth
|
||||||
|
if (ww > window.screen.width) {
|
||||||
|
window.requestAnimationFrame(resize)
|
||||||
|
} else {
|
||||||
|
if (ww > 750) {
|
||||||
|
ww = 750
|
||||||
|
}
|
||||||
|
document.documentElement.style.fontSize = (ww * 100) / 750 + 'px'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resize()
|
||||||
|
|
||||||
|
window.addEventListener('resize', resize)
|
||||||
|
window.addEventListener('pageshow', function(e) {
|
||||||
|
if (e.persisted) {
|
||||||
|
resize()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})(window, document)
|
Loading…
x
Reference in New Issue
Block a user