Skip to content

Commit 78d61f2

Browse files
Bayn-Web包伟斌NataliaTepluhina
authored
doc(fix vuejs/core#11367):add a warn about '~' in src-imports (#3061)
* doc:add a warn about '~' in src-imports * Update src/api/sfc-spec.md Co-authored-by: Natalia Tepluhina <[email protected]> * Update src/api/sfc-spec.md Co-authored-by: Natalia Tepluhina <[email protected]> * doc(import statement): add import statement in script setup * doc(import statement): delete extraneous blank lines --------- Co-authored-by: 包伟斌 <[email protected]> Co-authored-by: Natalia Tepluhina <[email protected]>
1 parent 17041a2 commit 78d61f2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Diff for: src/api/sfc-script-setup.md

+14
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,20 @@ In addition, the awaited expression will be automatically compiled in a format t
479479
`async setup()` must be used in combination with [`Suspense`](/guide/built-ins/suspense.html), which is currently still an experimental feature. We plan to finalize and document it in a future release - but if you are curious now, you can refer to its [tests](https://github.com/vuejs/core/blob/main/packages/runtime-core/__tests__/components/Suspense.spec.ts) to see how it works.
480480
:::
481481

482+
## Import Statements {#imports-statements}
483+
484+
Import statements in vue follow [ECMAScript module specification](https://nodejs.org/api/esm.html).
485+
In addition, you can use aliases defined in your build tool configuration:
486+
487+
```vue
488+
<script setup>
489+
import { ref } from 'vue'
490+
import { componentA } from './Components'
491+
import { componentB } from '@/Components'
492+
import { componentC } from '~/Components'
493+
</script>
494+
```
495+
482496
## Generics <sup class="vt-badge ts" /> {#generics}
483497

484498
Generic type parameters can be declared using the `generic` attribute on the `<script>` tag:

Diff for: src/api/sfc-spec.md

+7
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ Beware that `src` imports follow the same path resolution rules as webpack modul
136136
</unit-test>
137137
```
138138

139+
:::warning Note
140+
While using aliases in `src`, don't start with `~`, anything after it is interpreted as a module request. This means you can reference assets inside node modules:
141+
```vue
142+
<img src="~some-npm-package/foo.png">
143+
```
144+
:::
145+
139146
## Comments {#comments}
140147

141148
Inside each block you shall use the comment syntax of the language being used (HTML, CSS, JavaScript, Pug, etc.). For top-level comments, use HTML comment syntax: `<!-- comment contents here -->`

0 commit comments

Comments
 (0)