英文:
How to use "iconClass" prop in a BalmUI "floating action button" component?
问题
我使用vue cli开始了一个BalmUI项目。在这个框架的某个组件中(我指的是浮动操作按钮),文档中提到我们可以在该组件的插槽中使用一个叫做iconClass的属性。文档中的示例如下:
<ui-fab>
<template #default="{ iconClass }">
<svg-logo :class="iconClass"></svg-logo>
</template>
</ui-fab>
但文档没有进一步解释这个属性的含义。这是材料图标的图标名称,还是我们可以为插槽添加自定义样式的类,还是其他什么?为了理解这个属性的含义,我创建了两个Vue组件。父组件名为HelloWorld.vue,包含以下代码:
<template>
<div class="hello">
<ui-fab>
<template #default="{ iconClass }">
<svg-logo :class="iconClass"></svg-logo>
</template>
</ui-fab>
</div>
</template>
<script>
import SvgLogo from '../components/SvgLogo.vue';
export default {
name: 'HelloWorld',
data() {
return {
iconClass: {
myClass: true
}
};
},
components: {
SvgLogo
},
}
</script>
<style lang="scss">
.myClass {
color: red;
font-size: 50px;
}
.iconClass {
color: red;
font-size: 50px;
}
</style>
第二个组件的代码如下:
SvgLogo.vue:
<template>
<div>
HD
</div>
</template>
<style scoped>
.myClass {
color: red;
font-size: 50px;
}
.iconClass {
color: red;
font-size: 50px;
}
</style>
但在我的结果页面中什么都没有发生。也就是说,没有样式应用到SvgLogo
组件上。我无法理解我的代码有什么问题,请帮我查找错误。
英文:
I started a project with BalmUI using vue cli. In one of the components that This framework has (I mean floating action button), The docs says that we can use a prop called iconClass in the slots of this component. The example in the docs is this one:
<ui-fab>
<template #default="{ iconClass }">
<svg-logo :class="iconClass"></svg-logo>
</template>
</ui-fab>
But it does not say anything else about this prop. Is this a icon name of material icons, or a class that we can add custom styles to the slot or anything else. I tried to understand the meaning of that prop by creating two vue components. The parent component is called HelloWorld.vue has these codes:
> HelloWorld.vue:
<template>
<div class="hello">
<ui-fab>
<template #default="{ iconClass }">
<svg-logo :class="iconClass"></svg-logo>
</template>
</ui-fab>
</div>
</template>
<script>
import SvgLogo from '../components/SvgLogo.vue';
export default {
name: 'HelloWorld',
data() {
return {
iconClass: {
myClass: true
}
}
}, // end of data
components: {
SvgLogo
},
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss">
.myClass {
color: red;
font-size: 50px;
}
.iconClass {
color: red;
font-size: 50px;
}
</style>
And the second component has these codes:
> SvgLogo.vue:
<template>
<div>
HD
</div>
</template>
<style scoped>
.myClass {
color: red;
font-size: 50px;
}
.iconClass {
color: red;
font-size: 50px;
}
</style>
But nothing happens in my result page. I mean that no style is applied to the SvgLogo
component. I could not understand what is wrong in my codes?
答案1
得分: 0
经过在我的应用程序中搜索并使用浏览器开发工具,我发现这个属性以及其他一些类似的属性在其他balmui组件的插槽中都是内部工作的。我的意思是它们不需要我们提供任何类或vue数据。例如,如果我们从以下代码中省略iconClass:
<ui-fab>
<template #default>
<svg-logo></svg-logo>
</template>
</ui-fab>
然后在浏览器开发工具中,我们可以看到类似于fab按钮的以下图像:
如果我们注意到该部分中的“HD”字样(来自svg-logo组件),则没有添加任何类。另一方面,使用iconClass属性:
<ui-fab>
<template #default="{ iconClass }">
<svg-logo :class="iconClass"></svg-logo>
</template>
</ui-fab>
我们可以在浏览器开发工具中看到类似于以下图像:
在这种情况下,将mdc-fab__icon
类添加到包含HD字样的div中。因此,balmui本身向该div添加了一些样式,如下所示:
由于文档没有提到这个属性,我以为它是一个我们必须在代码中添加的类名或数据,以自定义fab组件,但我对此有误解。
英文:
After some search in my app and using browser devtools, I found that this prop and also some other similar props in other balmui components slots, works internally. I mean that they don't need any class or vue data from us. If we omit the iconClass for example from that code:
<ui-fab>
<template #default>
<svg-logo></svg-logo>
</template>
</ui-fab>
Then in the browser devtools, we can see something like this image for the fab btn:
If we notice to the "HD" word in that part (that comes from svg-logo component), there is no class added to that. On the other hand with using iconClass prop:
<ui-fab>
<template #default="{ iconClass }">
<svg-logo :class="iconClass"></svg-logo>
</template>
</ui-fab>
We could see something like this image in the browser devtools:
In this case the mdc-fab__icon
class is added to that div containing HD word. So the balmui itself added some styles to that div like these:
Because the docs did not say anything about this prop, I thought that it is a class name or a data that we must add in our code to customize the fab component, But I was wrong about that.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论