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
// JSX: using {" "} to add whitespace | |
<div> | |
<b>1</b> | |
{" "} | |
<b>2</b> | |
</div> | |
// Vue renders as expected | |
<div> | |
<b>1</b> |
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
let { items } = this.props; | |
let children; | |
if (items.length > 0) { | |
children = ( | |
<ul> | |
{items.map(item => | |
<li key={item.id}>{item.name}</li> | |
)} | |
</ul> |
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
<template> | |
<input v-model="name" /> | |
</template> |
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
Vue.component('Counter', { | |
// define the template in the component | |
// or reference a template defined in the DOM | |
template: ` | |
<div> | |
<span>{{ nr }}</span> | |
<div> | |
`, | |
// internal state (aka. viewmodel) |
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
<template> | |
<div> | |
<span>{{ nr }}</span> | |
<div> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { nr: 0 }; |
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
<template> | |
<input :value="name" @change="update"/> | |
</template> | |
<script> | |
export default { | |
methods: { | |
update(event) { | |
this.name = event.target.value; | |
} |
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
// props declaration | |
export default { | |
props: ['name', 'age'] | |
} | |
// props declaration, validation & default values | |
export default { | |
props: { | |
name: String, |
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
// parent component | |
template: '<Child @save="saveData" />', | |
methods: { | |
saveData() {/**/}; | |
} | |
// child component | |
template: '<button @click="onClick">Save</button>', | |
methods: { |
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
// global Event Bus | |
const eventBus = new Vue(); | |
/* ... */ | |
// some deeply nested component | |
methods: { | |
onClick() { | |
// emit a custom event on the Event Bus, not on "this" component | |
eventBus.$emit('save'); |
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
export default { | |
template: ` | |
<transition name="slide"> | |
... | |
</transition> | |
` | |
} |
OlderNewer