首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
V2EX
›
USDT
›
全部回复第 2 页 / 共 2 页
回复总数
23
1
2
❮
❯
2023-08-07 14:20:07 +08:00
回复了
Juppiter
创建的主题
›
前端开发
›
Next.js 求助
看你用的是 pages router 还是 app router ,本质上从请求的 headers 里面判断
// 比方说拿 user agent
pages router:
export async function getServerSideProps({ req }: { req: NextRequest }) {
const headers = req.headers;
console.log('!!!', headers);
return { props: { ua: headers.get('user-agent') } };
}
app router:
// 注意不能在'use client'的文件里面用
import { headers } from 'next/headers';
export default function Home() {
const hs = headers();
console.log('>>>>>>>>>>>', hs.get('user-agent'))
return (
<main>
Your agent is: {hs.get('user-agent')}
</main>
)
}
2023-08-06 22:10:04 +08:00
回复了
hez2010
创建的主题
›
程序员
›
给 .NET 实现了 Const Generics
惊呆了,太牛逼了!
@
forgottencoast
抖个机灵,toy example: 不定长元组 Tuple<2, int, double> / Tuple<3, int, string, double>
然后说一个猜想,很可能不太对,比方说对于矩阵相关的:可能我有些 geometry 库需要对二维和三维的 point 做处理,也许就可以先写一个基础 lib ,实现 Vector<n>, Matrix<n>。然后 2D 的东西继承了 Vector<2>/Matrix<2>然后再加入其特有的 method ,3D 的也类似
2023-08-01 21:25:44 +08:00
回复了
humbass
创建的主题
›
Node.js
›
如何获得 class 内部的方法?
用 Reflect
class App {
constructor() {
// 如何在这里获得 App 下面的所有方法?
const {ownKeys, getPrototypeOf} = Reflect;
console.log('methods:', ownKeys(getPrototypeOf(this)));
// 多了一个 constructor ,自行 filter 下
}
play() {}
unplay() {}
pause() {}
dosome() {}
dosome2() {}
}
new App() // output: [ 'constructor', 'play', 'unplay', 'pause', 'dosome', 'dosome2' ]
1
2
❮
❯
关于
·
帮助文档
·
自助推广系统
·
博客
·
API
·
FAQ
·
Solana
·
3620 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 39ms ·
UTC 10:24
·
PVG 18:24
·
LAX 02:24
·
JFK 05:24
♥ Do have faith in what you're doing.
❯