E.G.
components/
TodoList.js
TodoItem.js
components/
TodoList.vue
TodoItem.vue
E.G.
components/
|- MyComponent.vue
components/
|- my-component.vue
E.G.
components/
|- BaseButton.vue
|- BaseTable.vue
|- BaseIcon.vue
components/
|- AppButton.vue
|- AppTable.vue
|- AppIcon.vue
components/
|- VButton.vue
|- VTable.vue
|- VIcon.vue
E.G.
components/
|- TheHeading.vue
|- TheSidebar.vue
E.G.
components/
|- SearchButtonClear.vue
|- SearchButtonRun.vue
|- SearchInputQuery.vue
|- SearchInputExcludeGlob.vue
|- SettingsCheckboxTerms.vue
|- SettingsCheckboxLaunchOnStartup.vue
<MyComponent/>
),只能用在元件、字符串模板和JSX中。E.G.
<!-- In single-file components, string templates, and JSX -->
<MyComponent/>
<!-- In DOM templates (HTML Blade) -->
<my-component></my-component>
<MyComponent>
與<my-Component>
,看起容易區分HTML元素,因前者不同處有兩個大寫英文字母,後者只有一條橫線。E.G.
<!-- In single-file components and string templates -->
<MyComponent/>
<!-- In DOM templates -->
<my-Component></my-Component>
<!-- Everywhere -->
<my-Component></my-Component>
E.G.
Vue.component('MyComponent', {
// ...
})
Vue.component('my-component', {
// ...
})
import MyComponent from './MyComponent.vue'
export default {
name: 'MyComponent',
// ...
}
E.G.
components/
|- StudentDashboardSettings.vue
|- UserProfileOptions.vue
E.G.
props: {
greetingText: String
}
<WelcomeMessage greeting-text="hi"/>
E.G.
<img
src="<https://vuejs.org/images/logo.png>"
alt="Vue Logo"
>
<MyComponent
foo="a"
bar="b"
baz="c"
/>
E.G.
<!-- In a template -->
{{ normalizedFullName }}
// The complex expression has been moved to a computed property
computed: {
normalizedFullName: function () {
return this.fullName.split(' ').map(function (word) {
return word[0].toUpperCase() + word.slice(1)
}).join(' ')
}
}
E.G.
computed: {
basePrice: function () {
return this.manufactureCost / (1 - this.profitMargin)
},
discount: function () {
return this.basePrice * (this.discountPercent || 0)
},
finalPrice: function () {
return this.basePrice - this.discount
}
}
E.G.
<input type="text">
<AppSidebar :style="{ width: sidebarWidth + 'px' }">
E.G.
<input
:value="newTodoText"
:placeholder="newTodoInstructions"
>
<input
v-bind:value="newTodoText"
v-bind:placeholder="newTodoInstructions"
>
<input
@input="onInput"
@focus="onFocus"
>
<input
v-on:input="onInput"
v-on:focus="onFocus"
>
<template v-slot:header>
<h1>Here might be a page title</h1>
</template>
<template v-slot:footer>
<p>Here's some contact info</p>
</template>
<template #header>
<h1>Here might be a page title</h1>
</template>
<template #footer>
<p>Here's some contact info</p>
</template>
明天將會繼續來看Style Guide剩餘的部分!
Resource
Vue.js style-guide