Skip to content

Instantly share code, notes, and snippets.

@euperia
Last active September 12, 2017 21:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euperia/4a224c9f869b81a73e7cdd2998cc7ce7 to your computer and use it in GitHub Desktop.
Save euperia/4a224c9f869b81a73e7cdd2998cc7ce7 to your computer and use it in GitHub Desktop.
Sample Vue.js 2 table with rows
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue 2 table example</title>
</head>
<body>
<div id="app">
<table width="90%" border="1" cellpadding="2" cellspacing="2" v-show="sites.length > 0">
<thead>
<tr>
<th></th>
<th>Site</th>
<th>URL</th>
</tr>
</thead>
<tbody>
<!--
You would usually use the default Vue component syntax here,
e.g, <scan-row></scan-row>, but this won't work with some elements.
So we use the root element and use the `is=""` attribute to denote the component name
-->
<tr is="scan-row" v-for="site in sites" :site="site"></tr>
<tbody>
</table>
</div>
<script type="text/x-template" id="tplScanRow">
<tr>
<td>{{ site.id }}</td>
<td>{{ site.name }}</td>
<td>{{ site.url }}</td>
</tr>
</script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script>
var sites = [
{"id":1,"name":"Google","url":"https:\/\/www.google.com.ie"},
{"id":2,"name":"Facebook","url":"https://www.facebook.com"},
{"id":3,"name":"Twitter","url":"https://twitter.com"}
];
Vue.component('scan-row', {
template: '#tplScanRow',
props: {'site': Object},
});
var vm = new Vue({
el: '#app',
data: {
sites: sites
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment