首先,我创建一个ES5函数,然后创建它的原型:
var Person = function() {};
Person.prototype.city = function() {return 'New York'}Run Code Online (Sandbox Code Playgroud)
我在这里没有错误.但是当我用ES6胖箭头功能创建相同的时候,我得到Cannot set property 'city' of undefined:
let Person = () => {};
Person.prototype.city = () => {return 'New York'}Run Code Online (Sandbox Code Playgroud)
为什么是这样?
我正在显示与搜索词相关的数据。此数据一次显示所有结果。
我想要做的是一次显示 6 个数据并将剩余的数据加载到滚动条上。
<li *ngFor="let category of categories">
{{ category.name }}
</li>
Run Code Online (Sandbox Code Playgroud)
如何在滚动上显示数据?
我正在使用MomentJS时区.但是,当我这样做时moment.tz.guess(),它会返回错误拼写的时区.
const timezone = moment.tz.guess();
console.log(timezone); //returns Asia/Katmandu instead of Asia/Kathmandu
Run Code Online (Sandbox Code Playgroud)
是的,我可以编辑js文件并更正拼写,但我担心其他国家也是如此.由于我不知道它,这可能会降低用户体验!
是预期这种行为还是有任何方法可以修复它?
我正在使用 Nuxt 和 Typescript。我创建了以下组件:
<template>
<div class="field">
<label class="label" v-if="typeof label !== 'undefined'">{{ label }}</label>
<div class="control">
<textarea
v-if="inputType === 'textarea'"
class="textarea"
@input="$emit('input', $event.target.value)"
></textarea>
<input
v-if="inputType === 'input'"
:type="type"
class="input"
@input="$emit('input', $event.target.value)"
>
</div>
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator"
@Component({})
export default class AppInput extends Vue {
@Prop({ type: String, required: false, default: "input" })
inputType!: string
@Prop({ type: String, required: false })
label!: string
@Prop({ type: String, required: false, default: "text" …Run Code Online (Sandbox Code Playgroud) 我运行cargo test并在实际测试文件之前和之后得到这个垃圾:
root@ub:~/backend/utils# cargo test
Finished test [unoptimized + debuginfo] target(s) in 0.21s
Running unittests (target/debug/deps/utils-d206bcff05f45684)
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Running tests/helpers.rs (target/debug/deps/helpers-21ab86543f613060)
running 1 test
test tests::test_add ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Doc-tests utils
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 …Run Code Online (Sandbox Code Playgroud) fn main() {
let mut str = "string".to_string();
// How do I push String to String?
str.push_str(format!("{}", "new_string"));
}
Run Code Online (Sandbox Code Playgroud)
那么,如何将格式化的字符串推入呢str?我不想串联。连接与推送有点相同,但我想知道如何推送String。
我想使用https://github.com/microsoft/vscode-webview-ui-toolkit中的一些 Web 组件。但我不知道如何在 Svelte 中使用它们,因为 svelte 将 Web 组件视为 svelte 组件。
当我尝试将它们用作时,
<script lang="ts">
import { Button } from "@vscode/webview-ui-toolkit"
</script>
<main>
<Button appearance="primary">Text</Button>
</main>
Run Code Online (Sandbox Code Playgroud)
我收到这个错误,
Element does not support attributes because type definitions are missing for this Svelte Component or element cannot be used as such.
Underlying error:
JSX element class does not support attributes because it does not have a '$$prop_def' property.ts(2607)
'Button' cannot be used as a JSX component.
Its instance type 'Button' is not …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
async [types.GET_DATA]({commit, state}, data) {
try {
const res = await axios.post('/login', {
email: data.email,
password: data.password,
});
console.log(res)
} catch(e) {
if(e.response) {
console.log(e.response)
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,每当用户发送空字段时,我都会返回 400 Bad Request。axios 所做的是将错误与错误响应一起抛出。我需要做的是删除该控制台错误消息并仅获得错误响应。
我该怎么做?
我有一个简单的 Vue 组件,根元素为ref="divRef". 然而,在onMounted函数中,divRef.value返回未定义。任何帮助将不胜感激。
import { defineComponent, onMounted, ref, Ref, h } from "vue"
export default defineComponent({
setup(props, context) {
const divRef = ref() as Ref<HTMLElement>
onMounted(() => {
console.log(divRef.value) // undefined
})
return () => {
return h(
"div",
{
ref: "divRef"
},
"This is a div"
)
}
}
})
Run Code Online (Sandbox Code Playgroud) 这是我的目录结构,
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Cargo.lock\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Cargo.toml\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 add.rs\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main.rs\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tests\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 add_test.rs\nRun Code Online (Sandbox Code Playgroud)\nadd.rs
pub fn add(a: u8, b: u8) -> u8 {\n return a + b;\n}\nRun Code Online (Sandbox Code Playgroud)\nmain.rs
pub mod add;\n\nfn main() {}\nRun Code Online (Sandbox Code Playgroud)\nadd_test.rs
#[cfg(test)]\nmod tests {\n #[test]\n fn add_test() {\n // how do I use add.rs module?\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n在add_test函数中如何测试 的add.rs函数add?
javascript ×6
rust ×3
vue.js ×3
angular ×1
axios ×1
console ×1
ecmascript-6 ×1
momentjs ×1
nuxt.js ×1
svelte ×1
typescript ×1
vuejs3 ×1