兄弟姐妹组件Vue.js之间的通信

我有一个问题,当我单击组件B上的插入文本按钮时,它将添加文本卡,该文本卡是组件A。问题是当重新加载页面时,文本区域和保存按钮再次显示。 注意A,B是兄弟姐妹

//组件A

<template>
  <div class="answer-text-container answer-inner-container">
    <div class="content-inner">
      <p class="answer-type">{{ text.type }}</p>
      <p v-show="!this.show" class="answer-text">{{ text.body }}</p>

      <textarea v-model="text.body" v-show="this.show" rows="3" class="edit-text-area border rounded" placeholder="Enter the text here"></textarea>
    </div>
    <div class="button-container" v-show="!this.show">
      <button type="button" @click="editText" class="btn btn-primary edit-text-btn">
        <i v-bind:class="[editTextString]"></i>
      </button>
      <button type="button" @click="$emit('delete')" class="btn btn-danger edit-text-btn">
        <i class="fas fa-trash-alt"></i>
      </button>
    </div>
    <button type="button" @click="editText" class="btn btn-success rounded" v-show="this.show">Save</button>
  </div>
</template>

<script>
export default {
  data: function() {
    return {
      show: 0,
      editTextString: "far fa-edit"
    };
  },
  props: ["text"],
  methods: {
    editText() {
      this.show = !this.show;
      console.log(this.text);
    },
    removeTextComp() {}
  }
};

//组件B

<template>
  <div class="toolbar-container mb-4">
    <div class="col-md-12 p-0 text-center">
      <div class="row mx-0">
        <div class="col-md-4 p-0 d-inline-block toolbar-sub-container">
          <a @click="insertText" href="#">
            <p>Insert Text</p>
          </a>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data: function() {
    return {};
  },
  mounted() {},
  methods: {
    insertText() {
      this.$parent.insertTextComp();
    }
  }
};
</script>
评论