stenciljs - 需要帮助为 Stencil 设置类名
问题描述
因此,在阅读了文档然后在 Stencil 上上了一堂 umedy 课后,我似乎仍然无法在我的对象上设置类名。例如我有以下
import { Component, h, Prop } from '@stencil/core'
@Component({
tag: 'my-button',
styleUrl: 'my-button.css'
})
export class MyButton {
@Prop() btext: string;
@Prop() btype: string;
render(){
let classNaming: string = '';
switch(this.btype) {
case "Primary":
classNaming += 'My-Button-CSS';
break;
case "Secondary"
classNaming += 'My-Button-CSS';
break;
}
return <button class={classNaming}>this.btext</button>
}
}
}
问题是课程永远不会出现在按钮上。我知道我在教程中看到的 react-bootstrap 中,但从未使用过 react,它们有 variant="" 这基本上是我想要构建的,并且没有运气让它工作,因为 Stencil 教程和高级项目很少。另一个问题是现有的类都是基于 1.8 的。
解决方案
您在第二种情况(情况“次要”)之后忘记了一个冒号(:),并且}
在文档的末尾有一个额外的内容。
最终代码应该是:
import { Component, h, Prop } from "@stencil/core";
@Component({
tag: "my-button",
styleUrl: "my-button.css",
})
export class MyButton {
@Prop() btext: string;
@Prop() btype: string;
render() {
let classNaming: string = "";
switch (this.btype) {
case "Primary":
classNaming += "My-Button-CSS";
break;
case "Secondary":
classNaming += "My-Button-CSS";
break;
}
return <button class={classNaming}>{this.btext}</button>;
}
}
推荐阅读
- azure-ad-b2c - 使用 Javascript 调用 Azure B2C 上的登录按钮
- include - 如何在 OpenEdge Progress-4GL 中启动外部程序
- flutter - 我如何使用提供者来使用 Future Int?
- java - 在函数中使用单独的 {} 块的目的是什么?
- unity3d - Unity 中的多个或单个 NetworkManager
- java - 为什么异常处理程序中的 RestartResponseException 不会重定向到其他页面?
- debugging - 有没有dbg!Rust 中的替代方案不会将元组分成这么多行?
- gatsby - 抓取时未显示元标记
- python - 当正在进行许多还原时,虚拟机的并行还原失败 (webvirtcloud)
- rspec - 我想使用 Capybara 和 rspec 验证页面上没有损坏的链接