vue97-props是只读的

<template>
  <div class="hello">
    <h3>{{ init }}</h3>
    <button @click="changeName">+1</button>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  //props是自定义属性 为当前属性定义初始值
  props:["init"],
  data() {
    return {
      count: 0,
    };
  },
  methods: {
    changeName() {
      //报错 this.props是只读的
      this.init++;
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
h3 {
  margin: 40px 0 0;
}
</style>

转存到data中

posted @ 2022-07-09 22:11  前端导师歌谣  阅读(119)  评论(0)    收藏  举报