如何在 Vue 3 中创建事件总线?
在 Vue 2 中,它是:
export const bus = new Vue();
Run Code Online (Sandbox Code Playgroud)
bus.$on(...)
bus.$emit(...)
Run Code Online (Sandbox Code Playgroud)
在 Vue 3 中,Vue不再是构造函数,而是Vue.createApp({});返回一个没有$on和$emit方法的对象。
对于从fetch接收到的 JSON,Body.json()是否比JSON.parse(responseText )快?
理论上Body.json()可以在其从接收第一字节尽快开始解码JSON ReadableStream从fetch。这是它的工作原理吗?还是等到所有字节都收到?
const response = await fetch(url);
const json = await response.json();
Run Code Online (Sandbox Code Playgroud)
const response = await fetch(url);
const text = await response.text();
const json = JSON.parse(text);
Run Code Online (Sandbox Code Playgroud)
那么,这些版本的代码之间有区别吗?
我想执行基本的 AES-CBC 解密。encData我有使用 128 位密钥加密的字符串rawKey,初始化向量defaultIV为零。我只想使用 Web Crypto API,而不使用第三方库。可以做吗?
window.crypto.subtle.decrypt当我在 Chromium 和Firefox中使用 Web Crypto API 时,它会抛出异常:(DOMException没有更多信息) 。OperationError: The operation failed for an operation-specific reason
到底是什么问题呢?
密钥和加密数据没问题,我已经在在线解密中检查过它(使用控制台输出中的十六进制字符串)。
代码:
!async function script() {
// ArrayBuffer to Hex String. https://stackoverflow.com/a/40031979/11468937
function buf2hex(buffer) {
return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
}
const defaultIV = new Uint8Array(16);
const rawKey = new Uint8Array([42, 40, 254, 9, 99, 201, 174, 52, 226, 21, 90, 155, 81, …Run Code Online (Sandbox Code Playgroud) I need to concat multiple files to a single file in reverse order.
The order of lines in the files should not be changed.
For example:
file 1.txt
1
2
Run Code Online (Sandbox Code Playgroud)
file 2.txt
3
4
Run Code Online (Sandbox Code Playgroud)
The expected result:
result.txt
3
4
1
2
Run Code Online (Sandbox Code Playgroud)
These command do not work as expected:
tac *.txt > result.txt just reverses the order of lines in the files and concat the files in ordinal order. (2 1 4 3)
cat $(ls -r) > result.txt …