兄弟姐妹组件之间的通信 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>

show:0是条目值。重新加载页面时,此值也会重新加载。因此,如果您希望在重新加载后的实际值为show,请使用 localStorage 或 vuex store。 还有一个,我的意思是,如果你的show值是布尔值,那就更好了。

最新更新