cmc-web/packages/common/hooks/useOperateItem.ts

17 lines
461 B
TypeScript
Raw Normal View History

2024-08-20 12:11:31 +00:00
import { Message } from 'element-ui'
export default function() {
// 添加值
const addItem = function (data: any, initData = {}) {
data.push(initData)
}
// 删除某组件的item值
const removeItem = function (data: any, index: number, required: boolean = true) {
if (required && data.length == 1) return Message({ message: '值不能少于一项', type: 'warning' })
data.splice(index, 1)
}
return {
addItem,
removeItem
}
}