dr_fg2
dr_fg2

Reputation: 87

change data value in vue component

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?

Upvotes: 0

Views: 725

Answers (1)

Jedupont
Jedupont

Reputation: 437

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

data(){
  return{
    show: true
  };
},

Upvotes: 1

Related Questions