在SF的多个函数中使用变量

时间:2021-01-13 02:52:36

标签: salesforce salesforce-lightning

如何在同一组件内的多个位置使用相同的变量值?

那么我如何声明 var val ='something'; 一次并在该组件内的多个函数中使用它。

({
   doInit: function(component, event, helper) {
       var val ='something';
       //rest of the code...
   },
   something: function(cmp, event, helper) {
       var val ='something';
       //rest of the code...
   },
   another: function(cmp, event, helper) {
       var val ='something';
       //rest of the code...
   }
)}

1 个答案:

答案 0 :(得分:0)

在 Lightning Aura 组件中,存储状态的位置在组件属性中。

您需要在标记中声明一个组件属性,在那里或在 doInit() 中为其分配一个默认值,然后在其他函数中访问或改变该值。

光环属性被记录here