<template>
<div class=" ">
<div>对象清空</div>
<h3></h3>
<h3></h3>
<h3></h3>
<h3></h3>
<h2></h2>
</div>
</template>
<script>
export default {
name: "name",
data() {
return {
ruleForm: {
name: "111",
age: "222",
number: "333",
},
};
},
mounted() {
this.spliceFun();
},
methods: {
spliceFun() {
//不建议使用this.ruleForm={}
for (let key in this.ruleForm) {
this.ruleForm[key] = "";
}
},
},
};
</script>
<style lang="scss">
h2 {
color: #007dff;
}
</style>
JS对象清空
最新推荐文章于 2024-07-17 16:31:28 发布
本文详细介绍了如何在JavaScript中彻底清空一个对象,包括使用`Object.keys`、`for...in`循环、`delete`关键字以及深拷贝等方法,并讨论了不同方法的优缺点及其适用场景。
摘要由CSDN通过智能技术生成