29
loading...
This website collects cookies to deliver better user experience
props: {
title: String,
likes: Number,
isPublished: Boolean,
commentIds: Array,
author: Object,
callback: Function
}
<input type="checkbox" @change="logStatus" />
methods: {
logStatus() {
const isOn = document.getElementById('thecheckbox').checked;
if( isOn ) {
console.log('Light is on');
} else {
console.log('Light is off');
}
}
}
data() {
return {
isOn = false
}
},
methods: {
logStatus() {
if(this.isOn) {
console.log('Light is on');
} else {
console.log('Light is off');
}
this.isOn = !this.isOn;
}
}
<div v-for=’car in cars’ v-if=’car.country =="Germany"' >
V-for
to loop through the list, some people would use V-if
like it is above to make the condition or filtering. This looks good however, Vue’s compiler prioritizes v-for
over v-if
and so your desired outcome might not be what you get and the list (imagine it has 1 million items) would be looped through every single time. This as you can already tell is not efficient at all, you can use computed properties to ensure this works well for you.<div v-for='car in counteryFilter'>
//....
computed: {
countryFilter: () => {
return this.cars.filter(function (car) {
return car.country =="Germany"
})
}
}
vue ui
localhost:8000