我搜索了很多东西,寻找一种解决基本通用组件的解决方案。
为此,我需要将整个对象数组传递到fundernal组件。
在这个机构组件上,我想使用来自“ dynamicpath”示例的prop的动态值,
我
import myComponentName from myPathVar
想在导入行上使用变量,这些变量来自_props。而且我不知道如何解决这个问题,如果可能的话,
我尝试了此问题,但没有起作用
const path = '../../examples/tagsProjectsa.json';
const abc = import(`${path}`).then(data => {
console.log(data);
});
但是无法找到模块
更新:
要回答这个问题:不,我们不能进行通用导入的ATM,所以我可以通过道具传递界面,这也没有工作 - > 道具?
所以我在道具上使用类型来传递通用对象。而且它有效,我无法定义通用类型,因为无法传递接口以获取类型
I searched a lot,for a solution to create a basic generic component.
For this i need to pass throught props an Array of Objects to a functionnal Component.
On this functionnal component i want to use dynamic values coming from Props like import MyDynamicName from "DynamicPath"
Example
import myComponentName from myPathVar
I want to use variables on an import line , this variables coming from _props . And i don't know how to solve this problem and if its possible
i tried this but didn't worked
const path = '../../examples/tagsProjectsa.json';
const abc = import(`${path}`).then(data => {
console.log(data);
});
but module can't be found
UPDATE :
TO Answer the question : No We can't do generic import atm so i trie to pass interfaces through props and this didn't worked too --> Is there a way to pass down an Interface through props?
So i use type on my props to pass my generic objects. And it worked , i wasn't able to define generic types because can't pass interfaces to get types
发布评论
评论(1)
静态导入无法使用陈述来解决动态说明符。从链接的文档中:
但是,您可以使用动态导入。这甚至使用 object urls 代码段下面:
Static import statements cannot be used to resolve a dynamic specifier. From the linked documentation:
However, you can resolve a dynamic specifier (e.g. a string held in a variable) using dynamic import. This even works using object URLs as seen in the code snippet below: