sf-utils2 sf-utils2
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
  • 快速开始

  • 基础-Base

  • 对象-Object

  • 数组-Array✨✨✨

  • 方法-Function

  • 字符串-String

  • 数学-Math

  • 文件-Buffer

    • 序言
    • arrayBufferToBase64【ArrayBuffer转Base64】
    • arrayBufferToText【ArrayBuffer读取文本】
    • base64ToArrayBuffer【Base64转ArrayBuffer】
    • base64ToBlob【Base64转Blob】
    • blobToArrayBuffer【Blob转ArrayBuffer】
    • blobToBase64【Blob转Base64】
    • blobToText【Blob转文本】
    • encodeTextByArrayBuffer【ArrayBuffer对象转化加密后的文本】
    • decodeTextByArrayBuffer【ArrayBuffer对象解密密后的文本】
    • textToArrayBuffer【文本转成ArrayBuffer对象】
      • 1.示例
      • 2.入参说明
      • 3.源码
    • textToBlob【文本转成Blob对象】
  • 节点-dom

  • 拓展

  • nodejs

目录

textToArrayBuffer【文本转成ArrayBuffer对象】

描述

将字符串转成 ArrayBuffer 对象 v3.3.2+

# 1.示例

点击转换
得到的arrayBuffer对象文本:
<template>
  <div class="flex flex-col">
    <div class="flex gap-8px">
      <el-input placeholder="请输入要文本" v-model="text" />
      <el-button class="flex-none" :disabled="!text" @click="onEncode">点击转换</el-button>
    </div>

    <el-divider />
    <div class="mt-4px max-h-400px overflow-y-auto">得到的arrayBuffer对象文本:{{ arrayBufferString }}</div>
  </div>
</template>

<script>
import { textToArrayBuffer } from 'sf-utils2'

export default {
  data() {
    return {
      text: '',
      arrayBufferString: ''
    }
  },

  methods: {
    async onEncode() {
      const arrayBuffer = await textToArrayBuffer(this.text)
      this.$message.warning('请查看控制台')
      console.log(arrayBuffer)
      this.arrayBufferString = JSON.stringify(Array.from(new Uint8Array(arrayBuffer)))
    }
  }
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
显示代码 复制代码 复制代码

# 2.入参说明

参数 说明 类型 是否必填 默认值
text 字符串 string 是

# 3.源码

/**
 * 将字符串转成uint8array 对象,二进制
 * @param text
 */
async function textToArrayBuffer(text: string): Promise<ArrayBuffer> {
  const encoder = new TextEncoder()
  return encoder.encode(text).buffer
}

export default textToArrayBuffer
1
2
3
4
5
6
7
8
9
10
上次更新: 2025/07/01, 14:52:29
decodeTextByArrayBuffer【ArrayBuffer对象解密密后的文本】
textToBlob【文本转成Blob对象】

← decodeTextByArrayBuffer【ArrayBuffer对象解密密后的文本】 textToBlob【文本转成Blob对象】→

Theme by Vdoing | Copyright © 2022-2025 bianpengfei
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×