#Value of boolean variable is ignored in if condition?

3 messages · Page 1 of 1 (latest)

distant saddle
#

Hello everyone.

I simply cannot understand, why the code in the else statement is executed, when the condition shouldn't allow it? I've been at it for a few hours so maybe I'm missing something. This worked just fine not too long ago when I was working on something entirely different and in another component. What am I missing?

#
 
const isEditTodo = computed(() => {
    return route.path.includes('edit');
});

onMounted(async () => {
        if(isEditTodo == true){
            const response = await axios.get(`/api/todos/${route.params.id}`);
            todo.value.due_date = moment().format('MM-DD-YYYY hh:mm');
            todo.value = response.data;
        }
    
})

const submitForm = async () =>{
    try {
        console.log(isEditTodo.value); //false
        if (isEditTodo == false){
            await axios.post('/api/todos', todo.value);
        }
        else {
            console.log(isEditTodo.value); // false
            await axios.put(`/api/todos/${route.params.id}`, todo.value);
        }
        router.push('/');
    } catch (error){
        console.error(error);
 
   }
vagrant juniper
#

You're only sharing partial code, but I'd assume isEditTodo is a reactive or something, not a simple boolean. So yes, your check would go through the else. If it's something like a reactive or computed you'd have to use isEditTodo.value to get the actual value