我有基本的反应类:
import React, { Component } from 'react';
class Children extends Component {
render() {
return (
<h1>Children</h1>
);
}
}
export default Children;
位于/scenes/Stash/Children/Children
。我希望import
像StashChildren
。
import {Children as StashChildren} from './scenes/Stash/Children/Children';
但我明白了:
45:88-101“出口'儿童'(导入'StashChildren')不是 发现在'_ / scenes / Stash / Children / Children'
如果我这样做:
import {Children} from './scenes/Stash/Children/Children';
一切正常。
答案 0 :(得分:1)
您可以通过
导入默认导出 import StashChildren from './scenes/Stash/Children/Children'
或
import {default as StashChildren} from './Children';
您只需要在所需名称下导入默认值。
答案 1 :(得分:0)
由于您已将子组件导出为默认导出,因此可以使用任何名称导入它。所以你只需要
import StashChildren from './scenes/Stash/Children/Children';
答案 2 :(得分:0)
由于您要导出默认值,因此可以调用
import Children as StashChildren from './scenes/Stash/Children/Children';
对于别名,只需删除括号:
class SwapValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value.present? || record.attr3.present?
record.errors.add(attribute, :invalid)
end
end
end