我有一個組件傳入數據,然後我需要在點擊時將該數據從true更改爲false。我爲此創建了一個名爲toggleClass
的方法,但它不起作用,我沒有收到任何錯誤。Vue js - 獲取方法在組件中工作
Vue.component('moustache', {
name: 'moustache',
props: ['type', 'img'],
template: `<li>
<p><strong>@{{ type }}</strong></p>
<img width="300" height="200" src="/img/image.jpg">
<button class="btn btn-primary" v-bind:class="{ active: isActive }" :data-type="type" @click="toggleClass">Vote</button>
</li>`,
data: function(){
return{
isActive: false
}
},
methods: {
toggleClass(){
isActive: true
}
}
});
new Vue({
el: '#app'
});
謝謝,這是一個贏家:) –