这是我的组件计算属性:
methods: {
addFavoritePlace(place_id) {
axios.post('/api/add-favorite-place', { place_id: place_id })
.then(response => {
// I need here force command.
});
},
},
computed: {
filteredPlaces: function () {
var is_open;
if (this.showOpened) {
is_open = 'open'
} else {
is_open = 'close'
}
return this.singlePlaces.filter((j) => {
return j.name.toLowerCase().match(this.search.toLowerCase();
});
}
}
我的标记:
<span @click="addFavoritePlace(place.id)" class="favorite-btn active" v-if="place.is_favorited == true">
<i class="icon-heart"></i>
</span>
<span @click="addFavoritePlace(place.id)" class="favorite-btn" v-else>
<i class="icon-heart"></i>
</span>
我需要再次在computed内调用过滤函数,以激活收藏按钮。
this.singlePlaces
中的数据即可。 - Thomas Ferro