localhost-front/src/stores/voteCommon.js
2025-02-18 11:12:06 +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,
};
}