我读过一篇关于JavaScript parseInt 的文章,其中有这个问题:
parseInt(0.5); // => 0
parseInt(0.05); // => 0
parseInt(0.005); // => 0
parseInt(0.0005); // => 0
parseInt(0.00005); // => 0
parseInt(0.000005); // => 0
parseInt(0.0000005); // => 5
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况?
我想将我的 vuejs 项目升级到基于类组件的打字稿,但我在 vue 问题的https://github.com/vuejs/rfcs/pull/17#issuecomment-494242121 中阅读:
更新:Class API 提案正在被删除。
那么现有的基于类组件的项目会发生什么?更重要的是,基于这篇文章: https://alligator.io/vuejs/using-typescript-with-vue/其说
由于我们没有使用类样式语法,因此您可以使用 as 关键字将数据声明为数据类型。
这种在 vue3.0 中使用 typescript 的方式安全吗?
是否有任何正确的解决方案来处理元素外部的点击?
有一些通用的解决方案,例如在没有 jquery 的情况下处理元素外部的点击:
window.onload = function() {
// For clicks inside the element
document.getElementById('myElement').onclick = function(e) {
// Make sure the event doesn't bubble from your element
if (e) { e.stopPropagation(); }
else { window.event.cancelBubble = true; }
// Place the code for this element here
alert('this was a click inside');
};
// For clicks elsewhere on the page
document.onclick = function() {
alert('this was a click outside');
};
};
Run Code Online (Sandbox Code Playgroud)
但问题是几乎所有项目在不同的组件中都有多个不同的弹出窗口,我应该处理它们的外部点击。
我应该如何在不使用全局 window.on 的情况下处理 click-outisde ?(我认为不可能将所有组件的外壳处理程序放入 window.on …
我一直在努力扩展console.log以制作一个彩色的,以保持堆栈跟踪到它被调用的位置。我尝试了一些解决方案,但最终达到了这一点:
export const colorizedLog = (
text: string,
status: keyof typeof ColorStatus = "dark",
...args: any
) =>
console.log.bind(
console,
`%c ${text}`,
`font-weight:bold; color: ${ColorStatus[status]}`,
...args
);
Run Code Online (Sandbox Code Playgroud)
有了这个小binding,我们将能够保留堆栈跟踪,但这里的问题是我们必须在最后使用它并添加一个烦人的额外内容(),因为返回值是函数本身,它是 的结果bind:
colorizedLog(
"Title:",
"info",
"This is a working example")();
Run Code Online (Sandbox Code Playgroud)
我阅读过的其他主要资源如下:
const colorizedLog = (text, color= "#40a7e3", ...args) =>
console.log.bind(
console,
`%c ${text}`,
`font-weight:bold; color:${color}`,
...args
);
colorizedLog("Title:", "#40a7e3", "This is a working example")();Run Code Online (Sandbox Code Playgroud)
我正在尝试在vue-enterprise-boilerplate 中使用打字稿。但是在这个问题https://github.com/chrisvfritz/vue-enterprise-boilerplate/issues/118 中已经说过流程存在一些问题。
我尝试了其他解决方案来使其工作,例如使用“vue add @vue/typescript”,但没有明确说明我应该选择哪个配置。
1? Use class-style component syntax?(y/N)
2? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? (y/N)
3? Convert all .js files to .ts? (y/N)
4? Allow .js files to be compiled? (y/N)
Run Code Online (Sandbox Code Playgroud)
编号 3q,告诉我选择 babel 到现代,而在那期作者告诉我:
使用 @vue/cli-plugin-typescript 而不是 @vue/cli-plugin-babel(同时删除 .babelrc.js)。
我也这样做了,但是我遇到了一些关于无法找到某些模块的新错误,当我尝试修复它们时,webpack 配置出现了一些新错误......是否有人尝试过这些步骤并且有一个关于这个问题的逐步解决方案。
I've recently faced with some redos attack issues.
Explain in simple steps:
Regex denial of services: it means the attacker can put some malicious/crafted inputs to bring your server down by making it impossible to stop to finding the correct pattern, so it takes your whole CPU, and finally causing internal server error.
e.g. if you have a pattern like ^((ab)*)+$, and the attacker put a malicious input like abababababababababababababababababa it will cause a catastrophic error:

The …
我正在使用 vue 组合 API 并使用 ref 来表示对象数组,每个对象都有一个 value 属性,似乎打字稿将 ref 的值与每个数组内的属性值混淆了:
正如您在上图中看到的,打字稿告诉我们 arr 的类型是一个包含名称和值的对象数组,但是当我使用 ref 时,它检测到错误的类型。即使我使用如下所示的转换,问题也无法解决:
const arr2 = ref(arr as { name: string; value: number }[]);
Run Code Online (Sandbox Code Playgroud)
但是当我将 value 属性更改为 value2 或其他值时,它将起作用:

更新:
这是我今天遇到的另一个问题:
我想知道我应该如何解决这种类型错误?
我在打字稿中有一个枚举,如下所示:
export enum XMPPElementName {
state = "state",
presence = "presence",
iq = "iq",
unreadCount = "uc",
otherUserUnreadCount = "ouc",
sequenceID = "si",
lastSequenceID = "lsi",
timeStamp = "t",
body = "body",
message = "message"
}
Run Code Online (Sandbox Code Playgroud)
并想要解构它的价值,我们如何在 Typescript 中做到这一点?
const { uc, ouc, msg, lsi, si, t, body } = XMPPElementName;
Run Code Online (Sandbox Code Playgroud)
正如 @amadan提到的,我们可以Assigning to new variable names像 Mozilla 文档中所说的那样使用Destructuring_assignment,如下所示:
属性可以从对象中解包并分配给与对象属性名称不同的变量。
const { uc, ouc, msg, lsi, si, t, body } = XMPPElementName; …Run Code Online (Sandbox Code Playgroud) 我开发了一个vscode extension VSCodeWebDeveloperExperiencePack,现在我面临着其中一些之间的冲突,例如turbo console和deploy,我在扩展页面上编写了配置手册,如下所示:
ctrl+shift+psettingsPrefrences: Open settings (JSON)打开您的settings.json 文件 "workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "Atom One Dark",
"files.autoSave": "afterDelay",
"editor.fontFamily": "Fira Code",
"editor.fontLigatures": "",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.fontSize": 16,
"window.zoomLevel": 1,
"sync.gist": "70a5fe700fe4e46aebdf678a5c1db398",
"typescript.preferences.importModuleSpecifier": "non-relative",
"local-history.exclude": [
"**/.history/**",
"**/.vscode/**",
"**/node_modules/**",
"**/typings/**",
"**/out/**",
"**/Code/User/**"
]
Run Code Online (Sandbox Code Playgroud)
另外,还有一些keybindings配置如下:
[
{
"key": "ctrl+shift+alt+l",
"command": "bookmarks.jumpToNext",
"when": "editorTextFocus"
},
{
"key": "ctrl+alt+l",
"command": "-bookmarks.jumpToNext",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+alt+k", …Run Code Online (Sandbox Code Playgroud) 目标是找到在短语之间可能包含停用词列表的所有句子,to_match如下所示:
let stopword: string[]= ["of", "the", "a"];
let to_match : string = "make wish";
let text: string = "make wish wish make a wish wish wish make the a wish make";
Run Code Online (Sandbox Code Playgroud)
我只能make wish使用这个正则表达式进行匹配:
const regex = new RegExp(`(?:\\b)$to_match(?:\\b)`, "gi");
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以做类似的事情
let to_match_splitted: string[] = to_match.split(" ");
const regex = `(?:\\b)${to_match_splitted[0]}\s(${any(stopword)}?)+\s${to_match_splited[1]}(?:\\b)`;
Run Code Online (Sandbox Code Playgroud)
与any(stopword)停用词列表中的任何停用词相匹配。
to_match_splitted并且有一个正则表达式,无论列表中每个字符串之间有一个或多个停用词的长度如何,都可以工作。
typescript ×8
javascript ×7
vue.js ×3
regex ×2
vuejs2 ×2
bind ×1
console.log ×1
ddos ×1
destructure ×1
dom-events ×1
enterprise ×1
enums ×1
html ×1
node.js ×1
object ×1
parseint ×1
security ×1
typeerror ×1
vuejs3 ×1