首页 > 其他分享 >atob 或者btoa is not defined

atob 或者btoa is not defined

时间:2023-09-01 13:55:54浏览次数:41  
标签:b64Encoded defined global btoa Buffer atob

atob 或者btoa 方法是浏览器实现的而非 js 自带,需要需要使用这两个方法需要自己实现  最前面加上这段js 就可以使用了

global.Buffer = global.Buffer || require('buffer').Buffer;

if (typeof btoa === 'undefined') {
    global.btoa = function (str) {
        return new Buffer.from(str).toString('base64');
    };
}
if (typeof atob === 'undefined') {
    global.atob = function (b64Encoded) {
        return new Buffer.from(b64Encoded, 'base64').toString();
    };
}

  

标签:b64Encoded,defined,global,btoa,Buffer,atob
From: https://www.cnblogs.com/yoyo1216/p/17671673.html

相关文章

  • 2023-08-26 关于JSON.stringify会过滤调undefined值的问题 ==》在格式化之前先用type
    今天传参给后端的时候就发现了这么个问题,明明对象里面有这个字段a,但是打印出来死活没有,去掉json格式化后才发现是该值a为undefined,遂百度,故得知该值会被过滤掉。被过滤掉的原因是因为undefined值不符合JSON.stringify的规范。......
  • error: undefined reference to `cv::imread(cv::String const&, int)' 解决方法
    方法1原文链接:https://blog.csdn.net/WhiteLiu/article/details/72901520编译时出现下列错误:undefinedreferenceto'cv::imread(cv::Stringconst&,int)'undefinedreferenceto'cv::String::deallocate()'undefinedreferenceto'cv::imread(cv::S......
  • 为什么我们应该避免使用undefined?
    在JavaScript中,undefined是一个特殊的值和全局变量,用于表示一个未定义的变量或属性。当一个变量被声明但未被赋予初始值时,它的值就是undefined。类似地,如果你访问一个对象的不存在的属性,也会得到undefined。为什么我们应该避免使用undefined?可读性差首先,使用undefined可......
  • Failed to execute 'btoa' on 'Window': The string to be encoded contains characte
    在使用浏览器内置APIbtoa()编码base64时:报错Failedtoexecute'btoa'on'Window':ThestringtobeencodedcontainscharactersoutsideoftheLatin1range报错信息解释:报错信息中指出字符串中包含了Latin1范围之外的字符,导致无法使用window.btoa进行解析。根据你提供......
  • JavaScript​​-null 、 undefined和布尔值
    null和undefined 概述 null与undefined都可以表示“没有”,含义非常相似。将一个变量赋值为undefined或null,老实说,语法效果几乎没区别。vara=undefined;//或者vara=null;上面代码中,变量a分别被赋值为undefined和null,这两种写法的效果几乎等价。在if语句中,它们都会被自......
  • Cannot read properties of undefined (reading 'nodeName')解释
     jquery.min.js:2UncaughtTypeError:Cannotreadpropertiesofundefined(reading'nodeName')解释 这个错误通常发生在尝试访问或操作一个undefined或null值的属性时。错误消息"Cannotreadpropertiesofundefined(reading'nodeName')"意味着在代码中的某个......
  • Vue中出现“‘xxxxx‘ is defined but never used”解决办法
    【解决办法】:在package.json或者.eslintrc.js中找到 eslintConfig 块,在其rules下加入"no-unused-vars":"off"即可,如下图然后重新npmrunserve即可。其他命令如下:"no-alert":0,//禁止使用alertconfirmprompt"no-array-constructor":2,//禁止使用数组构造器"no-bitwis......
  • mysql在安装group_replication插件时,报错"version libcrypto.so.10 not defined in fi
    问题描述:mysql在安装group_replication插件时,报错"versionlibcrypto.so.10notdefinedinfilelibcrypto.so",如下所示:数据库:mysql8.0.27系统:rhel7.364位1、异常重现mysql>installplugingroup_replicationsoname'group_replication.so';ERROR1126(HY000):......
  • typeScript学习-TS类型-null和undefined
    typeScript学习null和undefinedundefinedanyunknown 可以接受undefinedletdata:undefined=undefinedletdata2:any=undefinedletdata3:unknown=undefined nullanyunknown 可以接受nullletdata4:null=nullletdata5:any=nullletd......
  • swagger显示示No operations defined in spec的解决
    背景:Spring2.6集成swagger2.0,启动后访问:http://localhost:80/swagger-ui/index.html,报错:Nooperationsdefinedinspec!查询资料的好几种结果:1.swagger解析的包路径配置错误,需要修改basePackage路径,反复查看是正确的。2.扫描的类或者方法上没有配置:@APIZ或者@ApiOpera......