我正在使用 Next.js 13 中的实验app文件夹,它们已替换next/router为next/navigation,因此我useRouter相应地导入了挂钩。pathname我在路由器中没有看到该属性,该属性确实存在于next/router的路由器中。
类型“AppRouterInstance”上不存在属性“路径名”
我的用例是突出显示用户当前所在的导航栏中的链接。这是我尝试过的:
import Link from "next/link";
import { useRouter } from 'next/navigation';
const StyledNavLink: React.FC<NavLinkProps> = ({ to, children }) => {
const router = useRouter();
...
return (
<Link href={to} className={getNavLinkClass({isActive: router.pathname === to})}>
{children}
</Link>
);
};
Run Code Online (Sandbox Code Playgroud)
我可以做些什么来获取当前路径名或其他东西来将我的类添加到活动链接中吗?
我有两个文本框,其宽度比例应该为2:1,我可以使用flex做到这一点。但是,当我将字体大小更改为300%时,文本框的宽度将相等。
如何避免这种情况并使宽度保持2:1的比例?
这是代码:
input[type=text] {
font-size: 300%;
}
#b4 {
flex: 2;
}
#b2 {
flex: 1;
}
div {
display: flex;
width: 100%;
}Run Code Online (Sandbox Code Playgroud)
<div>
<input type="text" id="b4"></input>
<input type="text" id="b2"></input>
</div>Run Code Online (Sandbox Code Playgroud)
另外,我不想为任何文本框设置固定宽度。
我有这个结构,它有一个包含类型的字段 Option<serde_json::Value>
我希望能够在该字段中存储任何对象(即由任何结构创建的对象)。我目前使用的方法是首先将对象转换为 JSON 字符串(使用serde_json::to_string),然后再次将其转换为serde_json::Value使用serde_json::from_str。
我这样做是为了可以发送带有任意数据的不同类型的 JSON 请求。
那么,有没有办法将任何 serde-serializable 对象转换为serde_json::Value不做 a serde_json::to_stringand serde_json::from_str?如果我在这方面走错了路,请提出更好的建议,ty!
这是我的代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main(int arge, char *argv[])
{
FILE *f1;
char ch,*fn="~/lyrics/";
strcat(fn,argv[1]);
strcat(fn,".txt");
if( (f1 = fopen(fn,"r"))==NULL )
{
printf("\nWrong filename\n%s not found",argv[1]);
return;
}
while((ch=getw(f1))!=EOF)
{
printf("%c",ch);
}
}
Run Code Online (Sandbox Code Playgroud)
我使用对其进行gcc -g -o file file.c了编译,并且编译器未给出任何错误消息。但是当我运行它时,我收到错误消息:
Segmentation fault (core dumped)
Bad permissions for mapped region at address 0x8048659 at 0x402C36B: strcat
(in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) by 0x80484D6: main (lyrics.c:9)
Run Code Online (Sandbox Code Playgroud)
谁能帮帮我吗?
我是Java的新手,所以如果这是一个非常小的错误,请原谅我,这是
我的代码:
import java.io.*;
public class election
{
public static void main(String args[])
{
boolean x=false;
Ballot ballot=new Ballot();
int n;
while(x!=true)
{
System.out.println("Cast your vote to(1-5): ");
try
{
n=System.in.read();
System.out.flush();
ballot.add(n);
System.out.println("Enter 0 to exit, enter 1 to vote again: ");
n = System.in.read();
if(n==0)
{
x=true;
}
else
{
x=false;
}
}
catch(IOException e)
{
System.out.println("I/O Error");
System.exit(1);
}
}
}
}
class Ballot
{
int votes,spoilt;
int cand[] = new int[5];
//methods
void add(int n)
{ …Run Code Online (Sandbox Code Playgroud) 我想将字符串转换为整数.我知道有内置函数可以做到,但我仍然想知道为什么这个函数不起作用:
JS: - 保存为js1.js
function atoi(str)
{
l = str.length;
s2 = "0"
for(i=0;i<l;i++)
{
if(str.charAt(i) != '1' || str.charAt(i) != '2' || str.charAt(i) != '3' || str.charAt(i) != '4' || str.charAt(i) != '5' || str.charAt(i) != '6' || str.charAt(i) != '7' || str.charAt(i) != '8' || str.charAt(i) != '9' || str.charAt(i) != '0')
{
break;
}
s2 = s2.concat(str.charAt(i));
}
return Number(s2);
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<html>
<head>
<script src="js1.js">
</script>
<Script>
function printnum()
{
n = atoi(document.getElementById('numtxt').value)
document.write(n);
} …Run Code Online (Sandbox Code Playgroud) html ×2
javascript ×2
c ×1
css ×1
flexbox ×1
java ×1
next.js ×1
reactjs ×1
rust ×1
serde ×1
serde-json ×1
typescript ×1
valgrind ×1