问题陈述
在过去的几天里,我注意到 GitHub Copilot 每次提出代码片段建议时都会发出声音。起初,我以为我的电脑出了问题,担心键盘上的某个按键卡住了。我花了两天时间才弄清楚声音实际上是来自 GitHub Copilot。
另一个问题是,我检查了扩展程序的设置,发现与禁用它产生的声音无关,并且该插件没有更新到任何更高版本。
要求
我如何让这种声音消失,因为每次提出代码建议时它实际上都让我烦恼?
我有一个使用如下设置语法创建的 pinia 商店:
defineStore('id', () => {
const counter = ref(0)
return { counter }
})
Run Code Online (Sandbox Code Playgroud)
使用设置语法一切都运行良好,因为我可以重复使用其他 pinia 商店。
然而,现在我发现需要在其他页面上重新使用 Pinia 商店,但需要重置它们的状态。
例如,在 Vuex 中,我使用registerModule和unregisterModule来实现拥有一个新鲜商店。
注意:该$reset()方法仅针对使用对象语法定义的存储实现,因此这不是一个选项。
注 2:我知道我可以通过创建一个函数来手动完成此操作,在该函数中将所有状态值设置为其初始值
注3:我找到了$dispose,但它不起作用。如果 $dispose 是答案,那么它如何重置两个组件之间的存储?
如何Vue.$compile在 Vue 3 运行时中使用编译函数?我在Vue 2中使用该函数。例如:
Vue.compile('<custom-component />');
Run Code Online (Sandbox Code Playgroud) 我正在创建一个匹配功能,将 2 个体重相同的玩家配对。
目前它正在基于相同的重量工作。现在,我的目标是为每场比赛添加一个序列。例如。
*如果玩家 1参加了第 1 场比赛,那么玩家 1 的下一场比赛应该是第 4 场或第 6 场比赛。玩家的每场比赛应该至少有 3 个、最多 6 个间隙,然后才能再次匹配该特定玩家。
我在下面提供了当前的输出和目标输出。
const source = [
{
entryID: 1,
entryName: "player1",
weight: 1900,
class:[],
},
{
entryID: 2,
entryName: "player1",
weight: 1900,
class:[],
},
{
entryID: 3,
entryName: "player2",
weight: 1900,
class:[],
},
{
entryID: 4,
entryName: "player3",
weight: 1900,
class:[],
},
{
entryID: 5,
entryName: "player4",
weight: 1900,
class:[],
},
{
entryID: 6,
entryName: "player5",
weight: 1900,
class:[],
},
{ …Run Code Online (Sandbox Code Playgroud)对于以下代码,既不是 ES6,也不是“严格模式”,我预期结果为 'b',因为 的第二个声明foo应该覆盖第一个声明。但结果是“a”!
{
function foo() {
console.log('a');
}
}
function foo() {
console.log('b');
}
foo(); // 'a' ? Why not 'b'?
Run Code Online (Sandbox Code Playgroud)
当此代码被附加花括号括起来时,结果是预期的“b”。
{ // additional curly braces
{
function foo() {
console.log('a');
}
}
function foo() {
console.log('b');
}
foo(); // 'b' as expected!
} // end additional curly braces
Run Code Online (Sandbox Code Playgroud)
为了进一步说明,请考虑以下附加示例:
foo('before declaration'); // outcome: from outside block :before declaration
{
function foo(s) {
console.log('from inside block: ' + s);
}
}
function foo(s) {
console.log('from …Run Code Online (Sandbox Code Playgroud) 我有一个对象数组:
var arrObj = [
{ a: "11", b: "Test1" },
{ a: "22", b: "Test2" },
{ a: "33", b: "Test1" },
{ a: "44", b: "Test3" },
];
Run Code Online (Sandbox Code Playgroud)
我想检查是否存在具有特定属性值的对象a。如果存在,那么它应该返回 property 的值b。
的价值a永远是独一无二的。
例如,如果我正在寻找"11",那么它应该返回"Test1"。
我正在尝试安装 Yajra,这是一个 Laravel 包,用于通过 AJAX 选项处理 DataTables jQuery 插件的服务器端工作。但我遇到了这个问题并且无法解决这个问题。请问您有什么可以帮助我的吗?
[Composer\Downloader\TransportException] 下载https://repo.packagist.org/packages.json时出现curl错误28 :10000毫秒后连接超时
structuredClone或者lodash.cloneDeep无法克隆函数。
有没有办法从泛型中排除Function类型?
我尝试过object: Exclude<T, {[key: string|number|symbol]: any, apply: any, call: any}>和
,当对象作为类object: Exclude<T, Function>传入时,两者都会返回类型错误。this
function cloneAnythingButFunction1<T>(object: Exclude<T, {[key: string|number|symbol]: any, apply: any, call: any}>): T{
return structuredClone(object)}
function cloneAnythingButFunction2<T>(object: Exclude<T, Function>): T{
return structuredClone(object)
}
// Expect error:
cloneAnythingButFunction1(cloneAnythingButFunction1)
cloneAnythingButFunction2(cloneAnythingButFunction2)
// Expect no error:
class Test{
clone1(){
return cloneAnythingButFunction1(this) // error
}
clone2(){
return cloneAnythingButFunction2(this) // error
}
}
const test = new Test()
cloneAnythingButFunction1(test)
cloneAnythingButFunction2(test)
Run Code Online (Sandbox Code Playgroud)
有没有什么办法解决这一问题?
我正在使用 Typescript、Pinia 和 Vue3,并且有一个MenuButton组件,我希望能够传递用于菜单打开状态以及显示/隐藏操作的 Pinia 存储。应用程序中有几个不同的菜单,因此我希望能够将它们传入,并且它们都使用相同的工厂来定义商店。我正在尝试找出如何让所有这些都与打字稿一起使用。
// nav.store.ts\n\nimport { defineStore } from "pinia";\nimport { useStorage } from "@vueuse/core";\nimport type { RemovableRef } from "@vueuse/core";\n\nexport interface MenuStore {\n isOpen: RemovableRef<boolean>,\n toggle(force?: boolean) : void,\n open(): void,\n close(): void,\n}\n\ninterface State {\n isOpen: RemovableRef<boolean>;\n}\n\nfunction menuStoreFactory(id: string) {\n return defineStore(id, {\n state: () : State => ({\n isOpen: useStorage(`${id}-open`, false),\n }),\n\n actions: {\n toggle(force?: boolean) {\n this.isOpen = force != undefined ? force : !this.isOpen;\n },\n\n open() {\n this.isOpen = true;\n …Run Code Online (Sandbox Code Playgroud) this数组中函数的值是多少methodArray,它是 的属性myObject?另外,是methodArray[0]普通函数还是方法?
let myObject = {
property: "Prakhar",
methodArray: [
function () {
console.log(this);
},
],
};
myObject.methodArray[0]();Run Code Online (Sandbox Code Playgroud)
在浏览器中执行此代码时,它会打印数组。不知道为什么会这样?理想情况下,如果函数不是方法或者myObject函数是方法,则它应该是窗口对象(全局)。
将多个数组扁平化为一个数组的更好、更有效的方法是什么?
\n传播运算符:
\nlet arr = [];\nfor (const array of arrays) {\n arr.push(\xe2\x80\xa6array);\n}\nRun Code Online (Sandbox Code Playgroud)\n或者与.flat():
let arr = [];\nfor (const array of arrays) {\n arr.push(array);\n}\narr = arr.flat();\nRun Code Online (Sandbox Code Playgroud)\n我使用循环不仅仅是const arr = arrays.flat()因为我想测试一些非常具体的东西。
我必须获取或计算多个字符串中有多少个字符。例子:
var aText = [
"There are only 2 types of people in the world:",
"Girls and boys, any other thing? I don't know."
];
Run Code Online (Sandbox Code Playgroud)
两个字符串加起来超过 80 个字符。另一个注意事项是字符串可能不固定,因为它们可能会增加或减少。有没有办法在 JavaScript 中做到这一点?
我尝试使用aText.length,但这只返回变量中的字符串数量。在本例中只有 2 个。
javascript ×6
vue.js ×4
vuejs3 ×4
arrays ×2
pinia ×2
typescript ×2
algorithm ×1
composer-php ×1
curl ×1
laravel ×1
node.js ×1
packagist ×1
performance ×1
this ×1
vite ×1