划分组件,引用组件,复用组件,基操。
被引用的组件不用在内部 export default,引用组件时也不需要像 Vue 一样使用 components 选项注册,引进来,直接用就成,而且还自动样式隔离,爽歪歪。唯一一点注意一下:约定引入的组件使用大写字母开头,类似 React。
这是待引用的组件:Title.svelte:
<div>This is A Title.</div>
<style>
  div {
    font-weight: bolder;
    padding: 15px;
    font-size: 24px;
    color: #ccc;
  }
</style>
这是需要引用 Title 的 App.svelte 组件:
<script>
  import Title from "./Title.svelte";
</script>
<Title />
<div>This is a paragraph</div>

跟引入其他资源没什么区别,跟 Vue 和 React 相比少了一些导出的代码。
原文:https://www.cnblogs.com/aisowe/p/15245473.html