댓글 수정사항 없으면 submit 버튼 disabled 처리

This commit is contained in:
nevermoregb 2025-03-28 13:59:38 +09:00
parent 2baebdf1e9
commit 7fd115ddc7
2 changed files with 18 additions and 16 deletions

View File

@ -38,7 +38,7 @@
<textarea v-model="localEditedContent" class="form-control"></textarea> <textarea v-model="localEditedContent" class="form-control"></textarea>
<span v-if="editCommentAlert" class="invalid-feedback d-block text-start">{{ editCommentAlert }}</span> <span v-if="editCommentAlert" class="invalid-feedback d-block text-start">{{ editCommentAlert }}</span>
<div class="mt-2 d-flex justify-content-end"> <div class="mt-2 d-flex justify-content-end">
<SaveBtn class="btn btn-primary" @click="submitEdit"></SaveBtn> <SaveBtn class="btn btn-primary" @click="submitEdit" :isEnabled="disabled"></SaveBtn>
</div> </div>
</template> </template>
@ -142,6 +142,8 @@
}; };
const localEditedContent = ref(props.comment.content); const localEditedContent = ref(props.comment.content);
const isModifyContent = ref(props.comment.content);
const disabled = ref(false);
// //
const isComment = ref(false); const isComment = ref(false);
@ -182,6 +184,11 @@
watch( watch(
() => localEditedContent.value, () => localEditedContent.value,
newVal => { newVal => {
if (JSON.stringify(isModifyContent.value) == JSON.stringify(newVal)) {
disabled.value = false;
return;
}
disabled.value = true;
emit('inputDetector'); emit('inputDetector');
}, },
); );

View File

@ -1,23 +1,18 @@
<template> <template>
<button <button type="button" class="btn btn-primary ms-1" @click="$emit('click')" :disabled="!isEnabled">
type="button"
class="btn btn-primary ms-1"
@click="$emit('click')"
:disabled="!isEnabled"
>
<i class="bx bx-check"></i> <i class="bx bx-check"></i>
</button> </button>
</template> </template>
<script> <script>
export default { export default {
name: "SaveButton", name: 'SaveButton',
props: { props: {
isEnabled: { isEnabled: {
type: Boolean, type: Boolean,
default: true, // default: true, //
},
}, },
}, emits: ['click'],
emits: ["click"], };
};
</script> </script>