vue3给一个对象里的所有key值赋空值或者字符串

var data={a:1,b:2,c:9,d:4,e:5};
    console.log(Object.keys(data));//["a", "b", "c", "d", "e"]
    Object.keys(data).map((key,item)=>{
        console.log(key,data[key]);//key=>属性名    data[key]=>属性值
});

下面代码示例是再新增的时候清除我定义的对象里的值(可以看到对象属性太多了):

 
 //商品库接口
        interface goodsinfo {
            goodsId: any
            tenantId: any
            goodsName: any
            shortName: any
            secondId: any
            pinyin: any
            catId: any
            brandId: any
            barcode: any
            unitId: any
            unitName: any
            bigBarcode: any
            bigUnitId: any
            bigUnitName: any
            unitRate: any
            wholesalePrice: any
            salePrice: any
            status: any
            shelfLife: any
            origin: any
            grade: any
            weight: any
            size: any
            isTobacco: any
            tags: any
            sort: any
            keywords: any
            albumPics: any
            detailDesc: any
            detailHtml: any
            detailMobileHtml: any
            sourceType: any
            revision: any
            crtBy: any
            crtTime: any
            uptBy: any
            uptTime: any
        }

const goodsInfoModel = ref<goodsinfo>({
            goodsId: '',
            tenantId: '',
            goodsName: '',
            shortName: '',
            secondId: '',
            pinyin: '',
            catId: '',
            brandId: '',
            barcode: '',
            unitId: '',
            unitName: '',
            bigBarcode: '',
            bigUnitId: '',
            bigUnitName: '',
            unitRate: '',
            wholesalePrice: '',
            salePrice: '',
            status: '',
            shelfLife: '',
            origin: '',
            grade: '',
            weight: '',
            size: '',
            isTobacco: '',
            tags: '',
            sort: '',
            keywords: '',
            albumPics: '',
            detailDesc: '',
            detailHtml: '',
            detailMobileHtml: '',
            sourceType: '',
            revision: '',
            crtBy: '',
            crtTime: '',
            uptBy: '',
            uptTime: '',
        })

 

        //新增数据
        function onAddItem() {
            // dialogTitle.value = 'add'
            Object.keys(goodsInfoModel.value).forEach(key => (goodsInfoModel.value[key] = ''));
            insertDialog.value.receive('add', goodsInfoModel.value)
            insertDialog.value?.onConfirm()
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

庞胖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值