我的 GitHub 存储库: https: //github.com/safiullah7/legan
分支:redux
我正在关注本教程:https://tomanagle.medium.com/build-a-rest-api-with-node-js-typescript-mongodb-b6c898d70d61 ,但我无法连接到我的 mongodb。这是我尝试连接 mongodb 的代码文件:
import config from "config";
import log from "../logger";
function connect() {
const dbUri = config.get("dbUri") as string;
return mongoose
.connect(dbUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
log.info("Database connected");
})
.catch((error) => {
log.error("db error", error);
process.exit(1);
});
}
export default connect;
Run Code Online (Sandbox Code Playgroud)
编译器给出以下错误:
No overload matches this call.
Overload 1 of 3, '(uri: string, callback: CallbackWithoutResult): void', gave the following error.
Argument of type '{ useNewUrlParser: …
Run Code Online (Sandbox Code Playgroud) 我正在尝试检查我的 blazor web assembly 应用程序是否在移动设备上打开。为了那个原因,
我创建了一个 wwwroot/script.js 文件并添加了代码:
function isDevice() {
return /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini|mobile/i.test(navigator.userAgent);
}
Run Code Online (Sandbox Code Playgroud)
在index.html中添加了参考
然后在我的组件中:
@inject IJSRuntime JSRunTime
@code {
private string isDevice { get; set; }
private static bool mobile { get; set; }
protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
mobile = await JSRuntime.InvokeAsync<bool>("isDevice");
isDevice = mobile ? "Mobile" : "Desktop";
}
await base.OnAfterRenderAsync(firstRender);
}
}
Run Code Online (Sandbox Code Playgroud)
我在编译时收到错误:
方法“InvokeAsync”没有重载需要 1 个参数
检查文档后:https://learn.microsoft.com/en-us/dotnet/api/microsoft.jsinterop.jsruntime.invokeasync ?view=aspnetcore-5.0#Microsoft_JSInterop_JSRuntime_InvokeAsync__1_System_String_System_Object__ _
我将代码更改为具有第二个参数,如下所示:
mobile = await JSRuntime.InvokeAsync<bool>("isDevice", new object[] { }); …
Run Code Online (Sandbox Code Playgroud) c# asp.net-core blazor blazor-client-side blazor-webassembly
Github 链接: https: //github.com/safiullah7/legan 分支:Redux
在我的切片文件中,我有 IHome 类型的初始状态:
export interface IHome {
bannerContent: IBannerContent,
expertiseContent: IExpertiseContent,
industryExpertise: IIndustryContent
}
Run Code Online (Sandbox Code Playgroud)
当我在获取用户输入后更新视图中的bannerContent:IBannerContent时,我尝试将更新后的对象传递给函数“updateHomeContent”,但出现编译器错误:
Type 'IBannerContent' is not assignable to type 'void | IHome | WritableDraft<IHome>'.
Run Code Online (Sandbox Code Playgroud)
这是我的切片文件:
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { IHome } from '../../models/home';
import { RootState } from '../../store';
const initialState: IHome = {
bannerContent: {
heading: 'Legal asdad',
mainText: 'The asdasdasdasd',
bottomText: 'You can asdadsad you shortly',
},
expertiseContent: {
heading: 'LEGAL asdsad',
mainText: 'Our niche …
Run Code Online (Sandbox Code Playgroud) asp.net-core ×1
blazor ×1
c# ×1
javascript ×1
mongodb ×1
mongoose ×1
node.js ×1
reactjs ×1
typescript ×1