如何在Ember中创建常量类或帮助器?
类似于创建一个constants.js并添加
export const testme = 3;
export const testtoo = 4;
Run Code Online (Sandbox Code Playgroud)
然后在控制器中我
import constants from 'constants';
Run Code Online (Sandbox Code Playgroud)
您正确导出但导入错误导入应该如下所示
import { testme, testtoo } from './constants';
Run Code Online (Sandbox Code Playgroud)
但我会采取不同的方法,而不是创建哈希常量(在constants.js文件中)
export default { TEST1: '1', TEST2: '2' };
Run Code Online (Sandbox Code Playgroud)
然后导入就好
import CONSTANTS from 'constants'
CONSTANTS.TEST1 === '1'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2288 次 |
| 最近记录: |