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

17 lines
464 B
TypeScript
Raw Normal View History

2024-08-20 12:11:31 +00:00
import { Message } from 'element-ui'
2024-08-21 01:17:14 +00:00
export default function () {
// 添加值
2024-08-20 12:11:31 +00:00
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
}
}