-
Notifications
You must be signed in to change notification settings - Fork 918
Template Specification #1535
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
Draft
znck
wants to merge
1
commit into
vuejs:master
Choose a base branch
from
znck:template-spec
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Template Specification #1535
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Template Specification | ||
|
||
Vue.js uses an HTML-based template syntax that allows you to declaratively bind the rendered DOM to the underlying Vue instance’s data. All Vue.js templates are valid HTML that can be parsed by spec-compliant browsers and HTML parsers. | ||
|
||
For usage guide, please see the [template syntax documentation](https://vuejs.org/v2/guide/syntax.html). | ||
|
||
## Overview | ||
|
||
The purpose of this specification is to define syntax structure of template language. A well defined | ||
specification enables community to create tools like parsers, syntax highlighters etc. | ||
|
||
## Syntax | ||
|
||
The template document must include following parts, in the given order: | ||
|
||
- Any number of [comments](https://html.spec.whatwg.org/multipage/syntax.html#syntax-comments) and [ASCII whitespace](https://infra.spec.whatwg.org/#ascii-whitespace) | ||
- An [element](#elements) | ||
- Any number of [comments](https://html.spec.whatwg.org/multipage/syntax.html#syntax-comments) and [ASCII whitespace](https://infra.spec.whatwg.org/#ascii-whitespace) | ||
|
||
### Elements | ||
|
||
The element section is extension of [HTML Element](https://html.spec.whatwg.org/multipage/syntax.html#elements-2). The element section in template adds following condition: | ||
|
||
- Disallows usage of `style` and `script` [raw text elements](https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements). | ||
- [Attributes](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2) include special kind of attributes called [directives](#directives) | ||
- Text can include [interpolation](#interpolation) | ||
|
||
### Directives | ||
|
||
The directive is extension syntax of [attributes](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2). | ||
Directives for an element are expressed inside the element's start tag. | ||
|
||
It must include following parts: | ||
|
||
- Directive [name or longhand](#directive-name) or [shorthand](#directive-shorthand) | ||
- Optional [argument](#directive-argument) with `:` prefix if used with longhand syntax | ||
- Any number of [modifiers](#directive-modifiers) | ||
- Optional [value](#directive-value) | ||
|
||
There different kinds of directives: | ||
|
||
- Custom Directives: | ||
- Builtin Directives: | ||
- [v-for](#for-directive) | ||
- [v-if](#if-directive) | ||
- [v-slot](#slot-directive) | ||
|
||
#### Directive Name | ||
|
||
The directive name has same syntax as [attribute name](https://html.spec.whatwg.org/multipage/syntax.html#syntax-attribute-name) with a constraint that it must hav `v-` prefix. The directive name includes builtin directives and custom directives defined by end user. | ||
|
||
#### Directive Shorthand | ||
|
||
The directive shorthand is single character replacement for directive name. Shorthand syntax is defined for some of builtin directives and custom directives cannot have shorthand. | ||
|
||
Directive | Shorthand | | ||
----------|:----------:| | ||
`v-bind` | `:` | | ||
`v-on` | `@` | | ||
`v-slot` | `#` | | ||
|
||
#### Directive Argument | ||
|
||
The directive argument can be specified in two different ways: | ||
|
||
##### Static Directive Argument | ||
|
||
The static argument is an alpha numeric case insensitive string. | ||
|
||
##### Dynamic Directive Argument | ||
|
||
The dynamic directive argument must include following parts: | ||
|
||
- The string `[` | ||
- A JavaScript expression which must not include following characters: | ||
- `\t` (tab) | ||
- `\r` (carriage return) | ||
- `\n` (new lint) | ||
- `\f` (form feed) | ||
- (space) | ||
- `]` (closing square bracket) | ||
- `/>` or `>` | ||
- The string `]` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.