admin管理员组文章数量:1434388
I have some problems implementing props in style tag. I have props like:
props: {
icon: {
type: String,
required: true
},
label: {
type: String,
required: true
}
}
And I want to use label props in Style, like:
<style scoped lang="scss">
.class{
color: label;
}
</style>
is that possible? Because it's not working like this
Idea is actually to make a call like:
.drop-color{
color: map-get($var, label);
}
This will work if I define it as;
.drop-color{
color: map-get($var, 'blue');
}
I just need to pass prop label instead.
I have some problems implementing props in style tag. I have props like:
props: {
icon: {
type: String,
required: true
},
label: {
type: String,
required: true
}
}
And I want to use label props in Style, like:
<style scoped lang="scss">
.class{
color: label;
}
</style>
is that possible? Because it's not working like this
Idea is actually to make a call like:
.drop-color{
color: map-get($var, label);
}
This will work if I define it as;
.drop-color{
color: map-get($var, 'blue');
}
I just need to pass prop label instead.
Share Improve this question edited Sep 8, 2021 at 12:11 Rade Iliev asked Sep 8, 2021 at 12:03 Rade IlievRade Iliev 2395 silver badges14 bronze badges 1- Check this answer - stackoverflow./a/42872117/10000229 – Zoha Malik Commented Sep 8, 2021 at 12:10
2 Answers
Reset to default 4With new script setup you're able to do it using v-bind
of vue 3.2.x:
<script setup>
import {defineProps} from 'vue'
const props = defineProps({
icon: {
type: String,
required: true
},
label: {
type: String,
required: true
}
})
</script>
<style scoped lang="scss">
.class{
color: v-bind(label);
}
</style>
LIVE DEMO
I don't think you can do that. v-bind
is runtime expression, whereas map-get
and other SASS specific things are transpiled to CSS at build time. So, if the key of the map is not available at build time, it won't build correctly.
But, you can import SASS variables and maps into JS and use them instead.
I don't know if SASS's builtin :export
supports maps, but if it doesn't you can use third party libraries like this one:
https://www.npmjs./package/sass-export
本文标签: javascriptVue 3 get props in styleStack Overflow
版权声明:本文标题:javascript - Vue 3 get props in style - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745630570a2667248.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论