这里写自定义目录标题
Vue箭头函数的使用
对象自变量中定义函数的原始做法
const obj = {
bbb(){
}
}
使用箭头函数放入多个参数
const sum (num1, num2) =>{
return num1 + num2
}
使用箭头函数放入一个参数,括号可以省略
const power = num =>{
return num * num
}`
函数中的代码数量问题
函数块中有多行代码的书写方式
const test = () =>{
//打印Hello Wolrd
consle.log("hello World");
//打印Hello Vuejs
consle.log("hello Vuejs");
函数代码块中只有一行代码
普通写法
const mul = (num1 + num2) => {
return num1 + num2
}
简便写法,他会执行这行代码,并将返回值返回,函数没有返回值时,会返回undefined
const mul =(num1, num2) => num1 + num2
箭头函数中this的使用
什么时候使用箭头函数
当我们打算把一个函数当作一个参数传入另一个函数中使用
箭头函数中的this引用的就是最近作用域中的this,this会向外曾作用域中,一层一层查找this,知道有this的定义