<template>
	<view class="content">
		<button type="primary" @click="setStorage">存储数据</button>
		<button type="primary" @click="getStorage">获取数据</button>
		<button type="primary" @click="delStorage">删除数据</button>
	</view>
</template>

<script>
	export default {
		methods: {
			setStorage() {
				uni.setStorage({
					key: 'name',
					data: 'uniapp',
					success() {
						console.log('存储数据')
					}
				})
			},
			getStorage() {
				uni.getStorage({
					key: 'name',
					success(res) {
						console.log('获取成功', res.data)
					}
				})
			},
			delStorage() {
				uni.removeStorage({
					key: 'name',
					success() {
						console.log('删除成功')
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐