0
<button id="btn1"> Button 1 </button>
<button id="btn2" v-if="state == 2"> Button 2 </button>

 export default {
        data() {
            return {
                emailPreferences: {
                    isLoading: false
                },
                state: 0 
            }
        },
       methods: {

        OnBtn1Click() {
            this.state = 2;
        }
      }
  }

I'm trying to show the button "btn2" when I click the Button 1. But it doesn't seems to work.

2
  • 2
    You don't appear to have registered a click listener on the button. @click="OnBtn1Click". Commented Jan 17, 2020 at 0:20
  • haha obviously ... :> Commented Jan 17, 2020 at 0:59

2 Answers 2

1

Just putting @skirtle's comment in an awnser:

new Vue({
  el: '#app',
  data: {
    state: 0 
  },
  methods: {
    OnBtn1Click() {
      this.state = 2;
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <button @click="OnBtn1Click" id="btn1"> Button 1 </button>
  <button id="btn2" v-if="state == 2"> Button 2 </button>
</div>

The logic of your code was fine, just had the 'onclick' property missing for the button

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

Comments

1

Add a click event on the button

<button @click="OnBtn1Click" id="btn1"> Button 1 </button>

Comments

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.