localhost-front/src/stores/voteCommon.js
2025-02-25 15:25:56 +09:00

27 lines
647 B
JavaScript

// voteCommon.js
import { ref } from "vue";
export function voteCommon(isVote= false) {
const itemList = ref(isVote ? [] : [{ content: "", url: "" }, { content: "", url: "" }]);
const addItem = () => {
if (itemList.value.length < 10) {
itemList.value.push({ content: "", url: "" });
}
};
const removeItem = (index) => {
if (!isVote && index >= 2) {
itemList.value.splice(index, 1);
} else if (isVote && itemList.value.length > 0) {
itemList.value.splice(index, 1);
}
};
return {
itemList,
addItem,
removeItem,
};
}