<template>
	<view>
		<view class="text-area">
			<button class="btnstyle" type="primary" @tap="arrayBufferToBase64"> arrayBufferToBase64 </button>
			<button class="btnstyle" type="primary" @tap="base64ToArrayBuffer"> base64ToArrayBuffer </button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
        arrayBufferToBase64Res:'',
        base64ToArrayBufferRes:''
			}
		},
		onLoad() {

		},
		methods: {
			arrayBufferToBase64() {
				const arraybuffer = new ArrayBuffer(3)
				const uint8 = new Uint8Array(arraybuffer)
				uint8.set([11, 22, 33])
				const base64 = uni.arrayBufferToBase64(arraybuffer)
				console.log(base64) //CxYh
        this.arrayBufferToBase64Res = base64
        uni.showToast({
           title:this.arrayBufferToBase64Res
        })
			},
			base64ToArrayBuffer() {
				const base64 = 'CxYh'
				const arrayBuffer = uni.base64ToArrayBuffer(base64)
				const uint8 = new Uint8Array(arrayBuffer)
				console.log(uint8.toString())//11, 22, 33
        this.base64ToArrayBufferRes = uint8.toString()
        uni.showToast({
           title:this.base64ToArrayBufferRes
        })
			}

		}
	}
</script>

<style>
	.logo {
		height: 100px;
		width: 100px;
		margin: 100px auto 25px auto;
	}

	.title {
		font-size: 18px;
		color: #8f8f94;
		text-align: center;
	}

  .btnstyle {
  	margin: 4px;
  }
</style>
