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/rules/README.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -353,6 +353,7 @@ For example:
353
353
|[vue/no-v-text](./no-v-text.md)| disallow use of v-text ||
354
354
|[vue/padding-line-between-blocks](./padding-line-between-blocks.md)| require or disallow padding lines between blocks |:wrench:|
355
355
|[vue/prefer-separate-static-class](./prefer-separate-static-class.md)| require static class names in template to be in a separate `class` attribute |:wrench:|
356
+
|[vue/prefer-true-attribute-shorthand](./prefer-true-attribute-shorthand.md)| require shorthand form attribute when `v-bind` value is `true`. |:bulb:|
356
357
|[vue/require-direct-export](./require-direct-export.md)| require the component to be directly exported ||
357
358
|[vue/require-emit-validator](./require-emit-validator.md)| require type definitions in emits |:bulb:|
358
359
|[vue/require-expose](./require-expose.md)| require declare public properties using `expose`|:bulb:|
description: require shorthand form attribute when `v-bind` value is `true`.
6
+
---
7
+
# vue/prefer-true-attribute-shorthand
8
+
9
+
> require shorthand form attribute when `v-bind` value is `true`.
10
+
11
+
-:exclamation: <badgetext="This rule has not been released yet."vertical="middle"type="error"> ***This rule has not been released yet.*** </badge>
12
+
-:bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
13
+
14
+
## :book: Rule Details
15
+
16
+
`v-bind` attribute with `true` value usually can be written in shorthand form. This can reduce verbosity.
However, those two representations are not always equivalent.
35
+
This case will be occurred if the definition of a prop include `String`:
36
+
37
+
```vue
38
+
<template>
39
+
<pre>{{ prop }}</pre>
40
+
</template>
41
+
42
+
<script>
43
+
export default {
44
+
name: 'MyComponent',
45
+
props: {
46
+
prop: [String, Boolean]
47
+
}
48
+
}
49
+
</script>
50
+
```
51
+
52
+
```vue
53
+
<template>
54
+
<MyComponent prop />
55
+
<MyComponent :prop="true"/>
56
+
</template>
57
+
```
58
+
59
+
Those two calls will introduce different render result. See [this demo](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbmltcG9ydCBNeUNvbXBvbmVudCBmcm9tICcuL015Q29tcG9uZW50LnZ1ZSdcbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG4gIDxNeUNvbXBvbmVudCBhIGIvPlxuICA8TXlDb21wb25lbnQgOmE9XCJ0cnVlXCIgOmI9XCJ0cnVlXCIvPlxuPC90ZW1wbGF0ZT4iLCJpbXBvcnQtbWFwLmpzb24iOiJ7XG4gIFwiaW1wb3J0c1wiOiB7XG4gICAgXCJ2dWVcIjogXCJodHRwczovL3NmYy52dWVqcy5vcmcvdnVlLnJ1bnRpbWUuZXNtLWJyb3dzZXIuanNcIlxuICB9XG59IiwiTXlDb21wb25lbnQudnVlIjoiPHNjcmlwdD5cbmV4cG9ydCBkZWZhdWx0IHtcbiAgcHJvcHM6IHtcbiAgICBhOiBCb29sZWFuLFxuICAgIGI6IFtTdHJpbmcsIEJvb2xlYW5dXG4gIH1cbn1cbjwvc2NyaXB0PlxuXG48dGVtcGxhdGU+XG4gIDxwcmU+XG5hOiB7e2F9fVxuYjoge3tifX1cbiAgPC9wcmU+XG48L3RlbXBsYXRlPiJ9).
0 commit comments