简体   繁体   English

更改 vue 组件中的数据值

[英]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我从 vue 开始,我正在测试单击按钮时更改值,但不工作

    <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?我如何访问变量并更改它?

You have declared your variable incorrectly, you should add show (and all your reactive variables) in the return:您错误地声明了变量,您应该在返回中添加show (以及所有反应变量):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM