<template>
<div>
<el-button @click="clickOut">ES6函数:方法设置默认值</el-button>
</div>
</template>
<script>
export default {
name: "index",
data() {
return {};
},
methods: {
//函数默认数值,如果不传age,那么age默认值就是3
getRefreshCodeFun2(name, age = 3) {
console.log(name, age);
},
//函数默认数值
getRefreshCodeFun3(arr1 = [], arr2 = []) {
console.log(arr1, arr2);
},
},
mounted() {
this.getRefreshCodeFun2("张三");
this.getRefreshCodeFun2("张三", 11);
this.getRefreshCodeFun3();
this.getRefreshCodeFun3([1, 2, 3]);
this.getRefreshCodeFun3([1, 2, 3], [2]);
},
};
</script>
<style scoped></style>
ES6函数:方法设置默认值
本文详细探讨了ES6中函数如何设置默认参数,解释了其语法特性、使用场景和注意事项,帮助开发者更好地理解和应用这一特性进行JavaScript编程。
摘要由CSDN通过智能技术生成