如何安装svelte
Svelte provides single file components. Every component is declared into a .svelte
file, and in there you can write the HTML markup, the CSS and the JavaScript needed.
Svelte提供单个文件组件。 每个组件都声明为一个.svelte
文件,您可以在其中编写HTML标记,所需CSS和JavaScript。
Here’s a simple Svelte component example, living in a file called Button.svelte
:
这是一个简单的Svelte组件示例,位于一个名为Button.svelte
的文件中:
<button>A button</button>
You can add CSS and JS to this component, but this plain HTML markup is already the markup of the component, there’s no need to wrap it in another special tag or anything.
您可以将CSS和JS添加到此组件中,但是这个普通HTML标记已经是该组件的标记,无需将其包装在另一个特殊标签或任何其他内容中。
To export this markup from this component you don’t have to do anything. You can now import it into any other Svelte component using the import ComponentName from 'componentPath'
syntax:
要从此组件导出此标记,您无需执行任何操作。 现在,您可以使用import ComponentName from 'componentPath'
语法中的import ComponentName from 'componentPath'
将其导入到其他任何Svelte组件中:
<script>
import Button from './Button.svelte';
</script>
And now you can use the newly imported component in the markup, like an HTML tag:
现在,您可以在标记中使用新导入的组件,例如HTML标签:
<Button />
如何安装svelte