是否有更简单的方法来编写以下复选框组件:
<script>
export let disabled = false;
</script>
{#if disabled}
<label class="checkbox" disabled>
<input type="checkbox" {disabled} />
<slot></slot>
</label>
{:else}
<label class="checkbox">
<input type="checkbox" {disabled} />
<slot></slot>
</label>
{/if}
Run Code Online (Sandbox Code Playgroud)
拥有<label disabled="false">是不可接受的,因为布尔玛有一个 CSS 类.checkbox[disabled]。
我正在关注这个Rust教程,并且正在努力编译第一个基础项目.我正在使用Fedora,但我是新手.
$ cargo build --verbose
Compiling sdl2-sys v0.5.0
Running `rustc /home/batisteo/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-sys-0.5.0/build.rs --crate-name build_script_build --crate-type bin -C prefer-dynamic -g --cfg feature="default" --out-dir /home/batisteo/arcade-rs/target/debug/build/sdl2-sys-d9571ac1c4bc4261 --emit=dep-info,link -L dependency=/home/batisteo/arcade-rs/target/debug/deps -L dependency=/home/batisteo/arcade-rs/target/debug/deps -Awarnings`
Fresh libc v0.1.8
Fresh bitflags v0.2.1
Fresh rustc-serialize v0.3.15
Fresh rand v0.3.8
Fresh num v0.1.25
error: could not exec the linker `cc`: No such file or directory (os error 2)
error: aborting due to previous error
Could not compile `sdl2-sys`.
Caused by:
Process didn't exit successfully: `rustc /home/batisteo/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-sys-0.5.0/build.rs --crate-name build_script_build …Run Code Online (Sandbox Code Playgroud) 如果 API 接受某些字节数限制的字符串值,但接受 Unicode,是否有更好的方法来缩短具有有效 Unicode 的字符串?
def truncate(string: str, length: int):
"""Shorten an Unicode string to a certain length of bytes."""
if len(string.encode()) <= length:
return string
chars = list(string)
while sum(len(char.encode()) for char in chars) > length:
chars.pop(-1)
return "".join(chars)
Run Code Online (Sandbox Code Playgroud) fedora ×1
html ×1
python ×1
python-3.x ×1
rust ×1
rust-cargo ×1
sdl-2 ×1
svelte ×1
svelte-3 ×1
unicode ×1