Learning Vue:
<!DOCTYPE html>
<html>
<head>
<title>My first Vue app</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<style>
</style>
</head>
<body>
<div id="app">
<friends v-for="friend in friends" :friend="friend"></friends>
</div>
<script>
Vue.component('friends', {
props : ['friend'],
template : `<table>
<tr><td>{{ friend.fname }}</td><td>{{ friend.lname }}</td></tr>
</table>`,
})
const vm = new Vue({
el : '#app',
data : {
friends : [
{fname : 'Cornelius', lname : 'Johnson'},
{fname : 'John', lname : 'Waybe'},
{fname : 'Neo', lname : 'Anderson'},
],
}
})
</script>
</body>
</html>
This works fine but it outputs several tables vs one table and it's rows.
I tried something like this
<div id="app">
<friends></friends>
</div>
Vue.component('friends', {
props : ['friends'],
template : `<table>
<tr v-for="friend in friends" :friend="friend"><td>{{ friend.fname }}</td><td>{{ friend.lname }}</td></tr>
</table>`,
});
const vm = new Vue({
el : '#app',
data : {
friends : [
{fname : 'Cornelius', lname : 'Johnson'},
{fname : 'John', lname : 'Waybe'},
{fname : 'Neo', lname : 'Anderson'},
],
}
})
But that just outputs an empty table.
How can I output just one table and its rows?