我有一个pages/index.tsxNext.js 页面,其代码如下所示:
import { ApolloProvider } from "@apollo/react-hooks"
import Client from "../db"
import Header from "../components/Header"
export default function Index() {
return <ApolloProvider client={Client}>
<Header langKey={langKey} />
</ApolloProvider>
}
Run Code Online (Sandbox Code Playgroud)
问题是,langKey应该是访问页面的子域(例如,en.localhost:3000or fr.localhost:3000;langKey将是enor fr)。如何从 Next.js 上下文中检索此信息?我尝试了 Router 对象,但它看起来不像在第一个/.
我正在使用 Node.js 编写一个小游戏,我希望以两种不同的语言提供该游戏。
为了显示不同游戏模式的翻译列表及其各自的描述,我使用了Array.prototype.map(callback, thisArg),但看起来 Node 忽略了thisArg参数:
sendMessage(translated[channel.id].modeList + modes.filter(a => {
if (typeof a === "string")
return true;
return false;
}).map(translated.modeDesc, translated[channel.id]).join("\n"));
Run Code Online (Sandbox Code Playgroud)
translated :
const translated = {
"chooseLang" : "Choose a language",
"invalidOption" : "Invalid option",
"modeDesc" : mode => {return mode + " : " + "<" + modes[0][mode].join("|") + ">\n = " + this.modeDescs[mode];},
"(channel id)" : global.en
};
Run Code Online (Sandbox Code Playgroud)
global.en :
const en = {
"modeList" : "Here is a list of …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用端口将URL传递给Javascript,以便将用户重定向到另一个页面.我写了一个port module包含我的项目所需的所有端口:
port module Utils exposing (..)
port changePage : String -> Cmd Event
Run Code Online (Sandbox Code Playgroud)
然后,我在我的Elm文件中导入它:
type Event = PageChange String
import Utils exposing (changePage)
Run Code Online (Sandbox Code Playgroud)
但是编译器不喜欢它:
It looks like the keyword `import` is being used as a variable.
8| import Utils exposing (changePage)
^
Rename it to something else.
Run Code Online (Sandbox Code Playgroud)
所以我将端口定义移动到主文件:
type Event = PageChange String
port changePage : String -> Cmd Event
Run Code Online (Sandbox Code Playgroud)
但是编译器仍然不同意:
Port `changePage` has an invalid type.
28| port changePage : String -> Cmd Event
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You …Run Code Online (Sandbox Code Playgroud) 我有这个
{ a |
b = { a.b |
c =
Utils.newC
a.b.c
}
}
Run Code Online (Sandbox Code Playgroud)
但编译器只是说"不":
-- SYNTAX PROBLEM ----------------------------------------------------- Main.elm
I ran into something unexpected when parsing your code!
43| b = { a.b |
^
I am looking for one of the following things:
"'"
"|"
an equals sign '='
more letters in this name
whitespace
Run Code Online (Sandbox Code Playgroud)
我现在不知道该怎么办.如何获得a与c财产b更改为新的价值?