概述
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()
}
最后
以上就是传统大树为你收集整理的vue3给一个对象里的所有key值赋空值或者字符串的全部内容,希望文章能够帮你解决vue3给一个对象里的所有key值赋空值或者字符串所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复