Ember.js'faker'没有定义

时间:2016-10-03 20:49:26

标签: ember.js ember-cli ember-cli-mirage

我正在尝试从回购站启动服务器,但由于以下错误而导致启动服务器出现问题:

ember serve


Livereload server on http://localhost:49152
Serving on http://localhost:4200/

mirage/factories/page.js: line 4, col 42, 'faker' is not defined.

1 error

mirage/scenarios/default.js: line 7, col 19, 'domain' is defined but never used.
mirage/scenarios/default.js: line 13, col 105, Missing semicolon.
mirage/scenarios/default.js: line 5, col 7, 'ads' is defined but never used.

3 errors

===== 2 JSHint Errors

page.js:

import { Factory } from 'ember-cli-mirage';

export default Factory.extend({
    permalink: function() { return '/' + faker.lorem.words(1); }
});

这里有什么问题?我也使用npm手动安装faker,但它似乎没有任何影响,我仍然坚持这个错误。

2 个答案:

答案 0 :(得分:1)

faker应该包含在ember-cli-mirage命名空间中,因此只需将其与Factory一起导入:

import { Factory, faker } from 'ember-cli-mirage';

答案 1 :(得分:0)

faker未定义,因此代码应该包含以下任何一个:

int('1',2) | (int('1',2)

import { Factory } from 'ember-cli-mirage';

let faker = {
  lorem: {
    words: function() {}
  }
};