Vue2中 this 能直接获取到data和methods的原因
methods中能直接访问this的原因
// 1.遍历methods对象;
for(let key in methods){
// 2.给每一个method的this改变方向,绑定到vue实例上。
vm[key] = typeof methods[key] === 'function' ?
methods[key].bind(vm) : function(){}
}
1
2
3
4
5
6
2
3
4
5
6
编辑 (opens new window)
上次更新: 2022/06/07, 05:17:41