Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import and export may only appear at the top level #4

Open
mescalchuan opened this issue Mar 8, 2019 · 1 comment
Open

import and export may only appear at the top level #4

mescalchuan opened this issue Mar 8, 2019 · 1 comment

Comments

@mescalchuan
Copy link

我希望使用react展现自己封装的组件的示例,于是在 md文件中这样写:

<desc>
    ...
</desc>
<style>
    ...
</style>
<script>
    import Counter from './h5/components/counter';
    export default class Application extends React.Component {
         ...
    }
</script>

页面上提示:Uncaught SyntaxError: unknown: 'import' and 'export' may only appear at the top level

原因是import被一个匿名函数包起来了:(function() { import Counter from ... })

请问这个问题怎么解决?难道不能用import吗?谢谢🙏

@njleonzhang
Copy link
Owner

njleonzhang commented Mar 8, 2019

不支持 import 语法,你应该尝试把这个组件挂到全局的变量上(通过作为 umd 组件),然后在你的文档代码里使用。

你可以参考这个文档的做法: https://github.com/sodalife/soui-react/blob/master/docs/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants