我们在使用vue做文本传输时,通常会使用base64编码,下面是我的代码
<template>
<div>
<textarea v-model="inputText"></textarea>
<button @click="tobase64">Base Text</button>
<div v-if="base64">{
{ base64 }}</div>
</div>
</template>
<script>
export default {
data() {
return {
inputText: '',
base64: ''
};
},
methods: {
tobase64() {
this.base64 = btoa(this.inputText); // 使用 btoa 方法将文本转换为 Base64 编码
}
}
};
</script>
<style scoped>
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
}
</style>
这里只是做一个转换的示范,使用javascript的内置方法btoa对文本进行转换
目前使用英文的话,是可以的,但中文会引发报错