当前位置: 首页 > news >正文

wordpress博客建站教程百度推广投诉电话

wordpress博客建站教程,百度推广投诉电话,常州微信网站建设,网站服务器租用需要什么材料利用uniapp做开发时,缓存数据是及其重要的,下面是同步缓存和异步缓存的使用 同步缓存 在执行同步缓存时会阻塞其他代码的执行 ① uni.setStorageSync(key, data) 设置缓存,如: uni.setStorageSync(name, 张三) ② uni.getSt…

 利用uniapp做开发时,缓存数据是及其重要的,下面是同步缓存和异步缓存的使用

同步缓存

在执行同步缓存时会阻塞其他代码的执行

① uni.setStorageSync(key, data)

设置缓存,如:

uni.setStorageSync('name', '张三')

② uni.getStorageSync(key)

获取缓存,如:

uni.getStorageSync('name')

③ uni.removeStorageSync(key)

移除缓存,如:

uni.removeStorageSync('name')

④ uni.clearStorageSync()

清空所有缓存,如:

uni.clearStorageSync()

⑤ uni.getStorageInfoSync()

获取缓存更详细的信息,正如缓存中所有的key,如:

let res = uni.getStorageInfoSync()
//  取出缓存中所有的key,数组形式,如['name','age', ...]
let allStorageKeys = res.keys

异步缓存

异步缓存不会阻塞代码的执行,但是需要利用回调的特点,即执行成功之后要执行的代码放success中,失败的代码放fail中,一定要执行的代码放complete中

① uni.setStorage(OBJECT)

设置缓存,如:

uni.setStorage({key: 'name',data: '张三'
})

② uni.getStorage(OBJECT)

获取缓存,如:

uni.getStorage({key: 'name',success: (storage) => {//  获取key对应的valueconsole.log('value: ', storage.data)}
})

③ uni.removeStorage(OBJECT)

移除缓存,如:

uni.removeStorage({key: removeAsyncKey.value
})

④ uni.clearStorage()

清空所有缓存,如:

uni.clearStorage()

⑤ uni.getStorageInfo(OBJECT)

获取缓存更详细的信息,正如缓存中所有的key,如:

uni.getStorageInfo({success: (res) => {//  取出缓存中所有的key,数组形式,如['name','age', ...]let allStorageKeys = res.keysconsole.log(allStorageKeys)}
})

uniapp案例

页面如下:

以下是用Vue3语法写的uniapp测试缓存的代码

<template><view class="root"><view class="asyncStorageBox"><view class="title"><text>异步缓存</text></view><view class="set"><text>key: </text><input type="text" v-model="setAsyncKey" /><text>value: </text><input type="text" v-model="setAsyncValue"/><button @click="setAsyncStorage">设置缓存</button></view><view class="remove"><text>key: </text><input type="text" v-model="removeAsyncKey"/><text style="visibility: hidden;">value: </text><input type="text" style="visibility: hidden;"/><button @click="removeAsyncStorage">清除缓存</button></view><view class="get"><text>key: </text><input type="text" v-model="getAsyncKey"/><text>value: </text><input type="text" disabled="false" style="border-style: none;" v-model="getAsyncValue"/><button @click="getAsyncStorage">获取缓存</button></view><view class="getAll"><view class=""><button @click="getAsyncAllStorage">所有缓存</button><button type="warn" @click="clearAsyncAllStorage">清空缓存</button></view><textarea name="" id="" cols="30" rows="6" disabled="false" v-model="computeAllAsyncKeyValue"></textarea></view></view><view class="syncStorageBox"><view class="title"><text>同步缓存</text></view><view class="set"><text>key: </text><input type="text" v-model="setSyncKey"/><text>value: </text><input type="text" v-model="setSyncValue"/><button @click="setSyncStorage">设置缓存</button></view><view class="remove"><text>key: </text><input type="text" v-model="removeSyncKey"/><text style="visibility: hidden;">value: </text><input type="text" style="visibility: hidden;"/><button @click="removeSyncStorage">清除缓存</button></view><view class="get"><text>key: </text><input type="text" v-model="getSyncKey" /><text>value: </text><input type="text" disabled="false" style="border-style: none;" v-model="getSyncValue"/><button @click="getSyncStorage">获取缓存</button></view><view class="getAll"><view class=""><button @click="getSyncAllStorage">所有缓存</button><button @click="clearSyncAllStorage" type="warn">清空缓存</button></view><textarea name="" id="" cols="30" rows="6" disabled="false" v-model="computeAllSyncKeyValue"></textarea></view></view></view>
</template>
​
<script setup>import {} from '@dcloudio/uni-app'import { computed, ref } from 'vue';//  异步缓存数据const setAsyncKey = ref('')const setAsyncValue = ref('')const removeAsyncKey = ref('')const getAsyncKey = ref('')const getAsyncValue = ref('')const allAsyncKeyValue = ref({})const computeAllAsyncKeyValue = computed(() => JSON.stringify(allAsyncKeyValue.value))/*** 异步缓存key、value*/function setAsyncStorage() {uni.setStorage({key: setAsyncKey.value,data: setAsyncValue.value})}/*** 异步获取数据*/function getAsyncStorage() {uni.getStorage({key: getAsyncKey.value,success: (storage) => {getAsyncValue.value = storage.data}})}/*** 异步清除缓存*/function removeAsyncStorage() {uni.removeStorage({key: removeAsyncKey.value})}/*** 异步清空所有缓存*/function clearAsyncAllStorage() {uni.clearStorage()}/*** 异步查询出所有缓存*/function getAsyncAllStorage() {uni.getStorageInfo({success: (res) => {let allStorageKeys = res.keysallAsyncKeyValue.value = {}for (let k of allStorageKeys) {uni.getStorage({key: k,success: (storage) => {allAsyncKeyValue.value[k] = storage.data}})}}})}//  同步缓存数据const setSyncKey = ref('')const setSyncValue = ref('')const removeSyncKey = ref('')const getSyncKey = ref('')const getSyncValue = ref('')const allSyncKeyValue = ref({})const computeAllSyncKeyValue = computed(() => JSON.stringify(allSyncKeyValue.value))/*** 同步缓存key、value*/function setSyncStorage() {uni.setStorageSync(setSyncKey.value, setSyncValue.value)}/*** 同步获取数据*/function getSyncStorage() {getSyncValue.value = uni.getStorageSync(getSyncKey.value)}/*** 同步清除缓存*/function removeSyncStorage() {uni.removeStorageSync(removeSyncKey.value)}/*** 同步清空所有缓存*/function clearSyncAllStorage() {uni.clearStorageSync()}/*** 同步查询出所有缓存*/function getSyncAllStorage() {let res = uni.getStorageInfoSync()console.log(res)let allStorageKeys = res.keysallSyncKeyValue.value = {}for (let k of allStorageKeys) {allSyncKeyValue.value[k] = uni.getStorageSync(k)}}</script>
​
<style lang="scss">.root {display: flex;flex-direction: column;.asyncStorageBox{display: flex;flex-direction: column;border: 1px solid black;margin-bottom: 20rpx;}.syncStorageBox{display: flex;flex-direction: column;border: 1px solid black;}.title {text-align: center;font-weight: bold;}.set {display: flex;flex-direction: row;input {margin-left: 20rpx;width: 150rpx;padding-left: 10rpx;border: 1px dotted #aaa;}button {height: 70rpx;line-height: 70rpx;margin-top: -10rpx;}margin: 30rpx 0;}.getAll{display: flex;margin-bottom: 20rpx;textarea {border: 1px solid black;width: 60%;margin-left: 50rpx;}button {height: 100rpx;margin-bottom: 50rpx;}}.get {display: flex;flex-direction: row;input {margin-left: 20rpx;width: 150rpx;padding-left: 10rpx;border: 1px dotted #aaa;}button {height: 70rpx;line-height: 70rpx;margin-top: -10rpx;}margin: 30rpx 0;}.remove {display: flex;flex-direction: row;input {margin-left: 20rpx;width: 150rpx;padding-left: 10rpx;border: 1px dotted #aaa;}button {height: 70rpx;line-height: 70rpx;margin-top: -10rpx;}margin: 30rpx 0;}}
</style>

http://www.yidumall.com/news/20526.html

相关文章:

  • 设计标志公司seo入门课程
  • 自己做的网站如何链接到百度沈阳优化推广哪家好
  • 网站导航html推广普通话绘画
  • 高大上的企业网站百度一下搜索
  • 网站导航是怎么做的深圳整站seo
  • 新手设计师接单网站百度一下你就知道官网网页
  • 做网站ps建立多大的画布南昌网站建设
  • 刚做的网站上线后收不到了怎么制作自己的网站
  • wordpress用户冻结免费seo网站推荐一下
  • 东营做网站免费正规的接单平台
  • 网站设计思路文案范文一个新产品的营销方案
  • 老网站删除做新站会影响收录吗php视频转码
  • 昆明电子商务网站建设广州疫情最新情况
  • 开发app用什么框架济南seo优化外包服务公司
  • 手机网站设计需要学什么深圳市住房和建设局官网
  • 单位网站建设ppt网站怎样被百度收录
  • 怎么在网上注册自己的网站带佣金的旅游推广平台有哪些
  • 阿里云建站百度收录吗网站功能
  • 重庆市住房和城乡建设委员会网站国内最新新闻事件
  • 广西壮族自治区皮肤病医院武汉网站优化公司
  • 自己建立网站要钱吗2022年热点营销案例
  • 全国个人信息查询系统windows优化大师下载安装
  • 滨州做网站的抖音seo优化系统招商
  • 如何入侵网站服务器深圳网络营销信息推荐
  • 牡丹江疫情最新政策seo站内优化
  • 欧 美 做 爱 视频网站seo百度快照优化公司
  • 商务网站建设的一般流程是什么广州百度seo代理
  • 网站开发网络公司餐饮店如何引流与推广
  • 如何建设网站使用seo快速排名优化
  • 网站做任务挣钱广点通推广登录入口