<p>我正在嘗試根據物件屬性綁定一個類,但是當我點擊列表物件觸發@click 時,控制台告訴我無法讀取isSelected 的物件屬性... 我正在嘗試在動態渲染的清單項目上使用函數來接收項目的id,並將此屬性設為false 或true 時觸發一個類別來啟動</p>
<p>希望有人能告訴我下面的程式碼中我漏掉了什麼,謝謝 :)</p>
<pre class="brush:php;toolbar:false;"><ul class="daysList">
<li v-for="day in January" v-bind:class="{addedToTrip: day.isSelected}" class="daynum" @click="toggleIsSelected(day)"daynum" @click="toggleIsSelected(day)"daynum:key=t; "day.id">
{{day.val}}
</li>
</ul></pre>
<p>我的 vue 資料</p>
<pre class="brush:php;toolbar:false;">data:function(){
return{
year: 2021,
month: 1,
day: 1,
days:[18,19,20,21],
January:[
{name: 'January', isSelected: false, id: 1, val:1},
{name: 'January', isSelected: false, id: 2, val:2},
{name: 'January', isSelected: false, id: 3, val:3},
{name: 'January', isSelected: false, id: 4, val:4},
{name: 'January', isSelected: false, id: 5, val:5},
{name: 'January', isSelected: false, id: 6, val:6},
{name: 'January', isSelected: false, id: 7, val:7},
{name: 'January', isSelected: false, id: 8, val:8},
{name: 'January', isSelected: false, id: 9, val:9},
{name: 'January', isSelected: false, id: 10, val:10},
{name: 'January', isSelected: false, id: 11, val:11},
{name: 'January', isSelected: false, id: 12, val:12},
{name: 'January', isSelected: false, id: 13, val:13},
{name: 'January', isSelected: false, id: 14, val:14},
{name: 'January', isSelected: false, id: 15, val:15},
{name: 'January', isSelected: false, id: 16, val:16},
{name: 'January', isSelected: false, id: 17, val:17},
{name: 'January', isSelected: false, id: 18, val:18},
{name: 'January', isSelected: false, id: 19, val:19},
{name: 'January', isSelected: false, id: 20, val:20},
{name: 'January', isSelected: false, id: 21, val:21},
{name: 'January', isSelected: false, id: 22, val:22},
{name: 'January', isSelected: false, id: 23, val:23},
{name: 'January', isSelected: false, id: 24, val:24},
{name: 'January', isSelected: false, id: 25, val:25},
{name: 'January', isSelected: false, id: 26, val:26},
{name: 'January', isSelected: false, id: 27, val:27},
{name: 'January', isSelected: false, id: 28, val:28},
{name: 'January', isSelected: false, id: 29, val:29},
{name: '一月', isSelected: false, id: 30, val:30},
{name: '一月', isSelected: false, id: 31, val:31},
],
二月:[],
行進:[],
四月:[],
可能:[],
六月:[],
七月:[],
八月:[],
九月:[],
十月:[],
十一月:[],
十二月:[],
}
},</pre>
<p>評價 isSelected == true 時的 css 類別</p>
.addedToTrip{
背景顏色:#2E9CFE;
頂部邊框:.5px 純黑色;
邊框底部:.5px 純黑色;
}</pre></p>
在指定類別名稱時,你需要使用單引號