:class="{'leftm':(index%2 == 1)}"
判斷index除以2取余等于1就用左邊的class
.leftm{
margin-left 1.6vw;
}
DEMO
CSS部分
.leftm{
width:100px;
? height:100px;
? background:yellow;
? float:right;
}
DIV部分
<div id="app">
? <div v-for="(item,index) in img" :class="{'leftm':(index%2 == 1)}">
? ? ? {{item}}
</div>
JS部分
? var app =new Vue({
el:'#app',
? ? data: {
// message: 'Hello Vue!',
? ? ? img:[
{
message:1,
? ? ? ? },
? ? ? ? {
message:1,
? ? ? ? }
]
}
})
console.log(1%2)
</script>