You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/start/spec.md
+72-1Lines changed: 72 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Vue Component Spec
2
2
3
-
A `*.vue` file is a custom file format that uses HTML-like syntax to describe a Vue component. Each `*.vue` file consists of three types of top-level language blocks: `<template>`, `<script>` and `<style>`:
3
+
A `*.vue` file is a custom file format that uses HTML-like syntax to describe a Vue component. Each `*.vue` file consists of three types of top-level language blocks: `<template>`, `<script>`, and `<style>`, and optionally additional custom blocks:
4
4
5
5
```html
6
6
<template>
@@ -22,6 +22,10 @@ export default {
22
22
color: red;
23
23
}
24
24
</style>
25
+
26
+
<custom1>
27
+
This could be e.g. documentation for the component.
28
+
</custom1>
25
29
```
26
30
27
31
`vue-loader` will parse the file, extract each language block, pipe them through other loaders if necessary, and finally assemble them back into a CommonJS module whose `module.exports` is a Vue.js component options object.
@@ -66,6 +70,66 @@ More details can be found in [Using Pre-Processors](../configurations/pre-proces
66
70
67
71
- By default, contents will be extracted and dynamically inserted into the document's `<head>` as an actual `<style>` tag using `style-loader`. It's also possible to [configure Webpack so that all styles in all components are extracted into a single CSS file](../configurations/extract-css.md).
68
72
73
+
### Custom Blocks
74
+
75
+
Additional custom blocks can be included in a `*.vue` file for any project specific needs. `vue-loader` will use the tag name to look up which webpack loaders should be applied to the contents of the section. The webpack loaders should be specified in the `loaders` hash of the `vue` section of the webpack configuration in the same way that languages are specified for the standard sections of the file. See [Advanced Loader Configuration](../configurations/advanced.md).
76
+
77
+
Example:
78
+
79
+
#### component.vue
80
+
```html
81
+
<unit-test>
82
+
describe('example', function () {
83
+
it('basic', function (done) {
84
+
done();
85
+
})
86
+
})
87
+
</unit-test>
88
+
89
+
<template>
90
+
<h2class="red">{{msg}}</h2>
91
+
</template>
92
+
93
+
<script>
94
+
exportdefault {
95
+
data () {
96
+
return {
97
+
msg:'Hello from Component A!'
98
+
}
99
+
}
100
+
}
101
+
</script>
102
+
103
+
<style>
104
+
comp-ah2 {
105
+
color: #f00;
106
+
}
107
+
</style>
108
+
```
109
+
110
+
#### webpack.config.js
111
+
112
+
```js
113
+
// Webpack 2.x (^2.1.0-beta.25)
114
+
module.exports= {
115
+
module: {
116
+
rules: [
117
+
{
118
+
test:/\.vue$/,
119
+
loader:'vue',
120
+
// vue-loader options go here
121
+
options: {
122
+
loaders: {
123
+
unit-test:'buble-loader',
124
+
}
125
+
}
126
+
}
127
+
]
128
+
}
129
+
}
130
+
```
131
+
132
+
69
133
### Src Imports
70
134
71
135
If you prefer splitting up your `*.vue` components into multiple files, you can use the `src` attribute to import an external file for a language block:
@@ -83,6 +147,13 @@ Beware that `src` imports follow the same path resolution rules to CommonJS `req
83
147
<stylesrc="todomvc-app-css/index.css">
84
148
```
85
149
150
+
`src` imports also work with custom blocks, e.g.:
151
+
152
+
``` html
153
+
<unit-test src="./unit-test.js">
154
+
</unit-test>
155
+
```
156
+
86
157
### Syntax Highlighting
87
158
88
159
Currently there is syntax highlighting support for [Sublime Text](https://github.com/vuejs/vue-syntax-highlight), [Atom](https://atom.io/packages/language-vue), [Vim](https://github.com/posva/vim-vue), [Visual Studio Code](https://marketplace.visualstudio.com/items/liuji-jim.vue), [Brackets](https://github.com/pandao/brackets-vue), and [JetBrains products](https://plugins.jetbrains.com/plugin/8057) (WebStorm, PhpStorm, etc). Contributions for other editors/IDEs are highly appreciated! If you are not using any pre-processors in Vue components, you can also get by treating `*.vue` files as HTML in your editor.
0 commit comments