【发布时间】:2021-07-20 14:04:50
【问题描述】:
所以当我执行以下操作时,我的一个 div 元素上的 :style 遇到了问题:
:style="(index + 1) % 2 == (0) && type.Liste.length === indexVin + 1 ? `margin-left : calc((100% - (100% / ${type.Liste.length})) + 6rem);` : null"
发生这种情况,您可以看到 style 属性为空
但是,如果我将我的 margin-left 更改为 margin-right 或 padding-left 它就可以了
我读到here 说margin-left 应该是camelCase 但我试过了,没有任何改变,奇怪的是margin-right 或padding-left 是kebab-case 并且工作得很好。
我不认为它来自我的速记,因为,每当我将我的 css 设置为除 margin-left 之外的任何东西时,它都会再次起作用,我还尝试在我的 div 上删除任何其他 css 源(所以只有我此处的设置已应用),但也没有用。
我的解决方案已经用完了,是的,我绝对需要它作为边距而不是填充
编辑:这里有更多代码,发生了最奇怪的事情,我的 console.log 工作得很好,在需要时触发,但由于某种原因,如果我将 margin-left 放在我的if(even)它不起作用但是margin-left 在进入else if(odd) 时有效,margin-right 相同,但方向相反,margin-right 仅在其位于if(even) 时有效,知道为什么吗?
methods : {
computedStyle(index , type , indexVin ) {
if ((index + 1) % 2 == (0) && type.Liste.length === indexVin + 1) {
console.log('even and last')
return `margin-left : calc((100% - (100% / ${type.Liste.length})) + 6rem);`
} else if (type.Liste.length === indexVin + 1) {
console.log('odd and last')
return `margin-right : calc((100% - (100% / ${type.Liste.length})) + 6rem);`
// return `'margin-left' : calc((100% - (100% / ${type.Liste.length})) - 6rem);`
// return 'background-color : red'
} else {
console.log('nothing special')
return null
}
},
}
<div class="padding-block-1" v-for="(type , index) in TypesDeVins" :key="index">
<div class="tw-flex tw-items-end slider-top"
:class="[LeftOrRight(index) , FlexDirection(index)]">
<div class="colonnes-resp-2 tw-flex-shrink-0" :class="LeftOrRightMargin(index , 2)">
<h4 class="tw-uppercase tw-font-bold text-1-2 letter-spacing-3"
:class="ColorTitle(index)">Les appellations</h4>
<h2 class="tw-uppercase tw-text-white tw-font-bold text-2-4 tw-mb-12 letter-spacing-4">{{ type.Nom }}</h2>
</div>
<div class="swiper-container" :class="`slider-top-${index}`" :dir="rtl(index)">
<div class="swiper-wrapper">
<div class="nom-vin swiper-slide" v-for="(vin , indexVin) in type.Liste"
:key="indexVin"
:class="slideDir(index)"
:style="computedStyle(index , type , indexVin)"
>
<h3 class="tw-text-white tw-font-bold tw-uppercase letter-spacing-3 text-1-2 tw-pb-12">{{ vin.title.rendered }}</h3>
</div>
</div>
</div>
</div>
</div>
【问题讨论】:
-
camelCase 用于对象,但在您上面的代码中的模板文字中,我们不需要使用 camelCase。我不认为这是
vue或margin-left的问题。你能告诉我更多代码或jsfiddle,以便我调试吗? -
添加了更多的 html,不幸的是我不能把它放在一个 jsfiddle 中,我正在将它用于目前仍在本地服务器上的无头 CMS
标签: javascript html css vue.js