在我的应用程序中,我有一个文件夹(见证),其index.js
包含下面提到的代码片段。
当我在index.js
中导出所有的Sagas,Reducer,容器,组件,然后想在app.js
中导入它们
import * as actions from './actions';
import * as components from './Components';
import * as constants from './constants';
import * as containers from './Containers';
import reducer from './reducers';
import * as sagas from './sagas';
export default {
actions,
components,
containers,
constants,
reducer,
sagas
};
现在,我该如何导入,比如说app.js
中的容器以及我写的时候
import Testimonial from './ignitus-Testimonial';
这是我导入对象并将其console.log()
放在app.js
上时的样子
Testimonail {操作:{…},组件:{…},容器:{…}, 常数:{…},减速器:ƒ,...}
但是我只想在我完成的所有导出中的containers
中使用app.js
。
答案 0 :(得分:1)
如果希望单独使用导出,则不应将它们作为default
导出导出。
它们可以重新导出为:
import * as actions from './actions';
import * as components from './Components';
import * as constants from './constants';
import * as containers from './Containers';
import reducer from './reducers';
import * as sagas from './sagas';
export {
actions,
components,
containers,
constants,
reducer,
sagas
};
它们可以单独导入为:
import { sagas } from './ignitus-Testimonial';
或一起作为:
import * as testimonial from './ignitus-Testimonial';
这种方法的问题在于,它会扼杀摇树优化,因此不建议将其用于输出大小很重要的用途,即客户端应用程序。
答案 1 :(得分:0)
使用如下所示的命名导入
// run this code to check random raindrop colors
// this project or codes are create Rain(loop) with different positions and colors.
// Show the positions of raindrop(x,y)
var xPositions = [200,100,250,350];
var yPositions = [0,-10,-30,-60];
// Draw function to repeat every raindrop position
draw = function() {
background(204, 247, 255);
// Condition to start back y position to do animation
if (mouseIsPressed) {
xPositions.push(mouseX);
yPositions.push(0);
}
// Loop the raindrop codes to repeat with some change
for (var i = 0; i < xPositions.length; i++) {
noStroke();
// fill random colors to the raindrop
fill(random(0,255),random(0,314),random(0,255));
// Raindrop
ellipse(xPositions[i], yPositions[i], 10, 10);
// Increase y position up to down everytime +=5
yPositions[i] += 5;
// Drops start back at the top once they've reached the bottom
if(yPositions[i] > 400) {
yPositions[i] = (0);
xPositions[i] = random(0,400);
}
}
};
答案 2 :(得分:0)
我自己解决了问题:)这样写就可以解决问题。 <Testimonial.containers.TestimonialContainer />