0

I'm starting with vue and I'm making a test to change a value when a button is clicked , but is not working

    <template>
  <div class="row">
    {{ show }}
    <div class="col-md-4">
      <button class="btn btn-primary" @click="change_show">Good</button>
    </div>
    <div class="col-md-4">
      <button class="btn btn-primary">Bad</button>
    </div>
    <div class="col-md-4">
      <button class="btn btn-primary">Food</button>
    </div>
  </div>
</template>

<script>
export default {
  name: "buttons",
  data(){
    return{
      show: true
    }
  },
  methods:{
    change_show(event){
      show = !show;
    }
  }
}
</script>

<style scoped>

</style>

I get this error

Uncaught ReferenceError: show is not defined

How I can access to the variables and change it?

1
  • place show within the return object Commented Jun 15, 2022 at 10:17

1 Answer 1

1

You have declared your variable incorrectly, you should add show (and all your reactive variables) in the return:

data(){
  return{
    show: true
  };
},
Sign up to request clarification or add additional context in comments.

2 Comments

I made show changes on the question but is still not working
@dr_fg2 try to add this keyword: this.show = !this.show;

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.