2

Vue renders v-if=true. But if I change bool true to false, vue doesn't re-render to v-else div.

How should it be? Is there any way to re-render?

Here is my code:

<template>
    <div v-if="bool">
        true
    </div>
    <div v-else>
        false // if button pressed, i should be shown!!!!
    </div>
    <button :click='onClickEvent()'>click!!!!!!</button>
</template>
<script>
    export default {
        data: function () {
            return {
                bool: true
            };
        },
        created() {
            
        },
        mounted(){
        
        }
        methods: {
            onClickEvent: function(){
                this.bool= false
            }
        }
    };
</script>

I tried everything I could think of.

1 Answer 1

1

You should not be binding with :click instead it should be @click="onClickEvent".

https://vuejs.org/guide/essentials/event-handling.html

Sign up to request clarification or add additional context in comments.

2 Comments

Since no arguments are passed to the handler, there is no need to use inline handler style here. Instead, you'd go for @click="onClickEvent"
@UliKrause I updated the answer to reflect this, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.