Example
// 全局模块引入
import { Base64 } from '@ccreator/smart-ui';
// 最小模块引入
import Base64 from '@ccreator/smart-ui/dist/Base64';
// 将对象编码为base64字符
const str = Base64.encodeJSON({ name: 'xx', value: 'xx' });
// 将base64字符解码为对象
const obj = Base64.decodeJSON(str);
const code = Base64.encode('测试的字符串');
const search = Base64.encodeURI('测试的字符串');
console.log(Base64.decode(code));
console.log(Base64.decode(search));
Methods
(static) decode(str)
使用base64解码字符串
Parameters:
Name | Type | Description |
---|---|---|
str |
String | 被解码字符串 |
Returns:
String 解码后的字符串
(static) encode(str)
使用base64编码字符串
Parameters:
Name | Type | Description |
---|---|---|
str |
String | 被编码字符串 |
Returns:
String 编码后的字符串
(static) encodeURI(str)
使用base64编码字符串(用于URL参数等)
Parameters:
Name | Type | Description |
---|---|---|
str |
String | 被编码字符串 |
Returns:
String 编码后的字符串
(inner) decodeJSON(str)
使用base64解码字符串为对象
Parameters:
Name | Type | Description |
---|---|---|
str |
String | 解码字符串 |
Returns:
Object 解码后的对象
(inner) encodeJSON(data)
使用base64编码对象为字符串
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | 编码对象 |
Returns:
String 编码后的字符串