1. 采用pako进行数据压缩
<template>
<div>
<button @click="handle">12121</button>
</div>
</template>
<script>
const pako = require('pako')
export default {
methods: {
handle() {
const test = {
title: '高校典型应用',
caseList: [
{
logo: 'https://m.vxiao.cn/commons/file/8x4xm6n1lsz1babwj1thcyst',
name: '通知书',
remark: '支持发送h5通知书,告知新生迎新流程'
}
]
}
const stringify = JSON.stringify(test)
const compressed = pako.deflate(stringify)
const strSize = unescape(encodeURIComponent(stringify)).length
const blobSize = new Blob([stringify]).size
console.log(strSize, 'strSize ')
console.log(blobSize, 'blobSize ')
console.log(compressed, 'compressed ')
const restored = JSON.parse(pako.inflate(compressed, { to: 'string' }))
console.log(restored, 'restored ')
}
}
}
</script>