gpt4 book ai didi

css - 如何在 Vue.js 3 中动态绑定(bind)样式属性?

转载 作者:行者123 更新时间:2023-12-01 23:42:44 25 4
gpt4 key购买 nike

我刚刚使用 vue3 并且想应用动态样式。我的 vue3 模板如下:

<ul>
<li v-for="(question, q_index) in questions" :key="q_index" v-show="question.visible" :style="{padding-left: `question.level`rem}">
<Question :title="question.title" :options="question.options" :name="question.id" :visible="question.visible" @opUpdate="opHandle"/>
</li>
</ul>

我的“-”模板有错误

Uncaught SyntaxError: Unexpected token '-'

如何在vue3模板中设置动态padding left css样式?

最佳答案

删除连字符并使用 template literal 就足够了:

<ul>
<li
v-for="(question, i) in questions"
:key="i" v-show="question.visible"
:style="{ paddingLeft: `${question.level}rem` }"
>
<Question
@opUpdate="opHandle"
:title="question.title"
:options="question.options"
:name="question.id"
:visible="question.visible"
/>
</li>
</ul>

附加:您还可以使用 v-bind 将对象项传递给具有相同名称的 Prop 。

<Question
@opUpdate="opHandle"
v-bind="question" // takes care of `title`, `options` and `visible`
:name="question.id"
/>

关于css - 如何在 Vue.js 3 中动态绑定(bind)样式属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64762871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com