move the contact template to the component

This commit is contained in:
Andreas Zweili 2021-01-25 12:33:19 +01:00
parent 1c6769e900
commit ce366e1f58
2 changed files with 17 additions and 8 deletions

View File

@ -23,9 +23,25 @@ const app = Vue.createApp({
// use multiword component names
app.component("user-contact", {
template: `
<li>
<h2>{{ friend.name }}</h2>
<button @click="toggleDetails()">Show Details</button>
<ul v-if="detailsAreVisible">
<li><strong>Phone:</strong> {{ friend.phone }}</li>
<li><strong>Email:</strong> {{ friend.email }}</li>
</ul>
</li>
`,
data() {
return {
detailsAreVisible: false,
friend: {
id: "manuel",
name: "Manuel Lorenz",
phone: "01234 5678 991",
email: "manuel@localhost.com",
},
};
},
methods: {

View File

@ -17,14 +17,7 @@
</header>
<section id="app">
<ul>
<li v-for="friend in friends">
<h2>{{ friend.name }}</h2>
<button @click="toggleDetails()">Show Details</button>
<ul v-if="detailsAreVisible">
<li><strong>Phone:</strong> {{ friend.phone }}</li>
<li><strong>Email:</strong> {{ friend.email }}</li>
</ul>
</li>
<user-contact></user-contact>
</ul>
</section>
</body>