This is my js and I already finsihed
var app = new Vue({
el: "#app",
data: {
column: {
id: "ID",
name: "Full Name",
phone: "Phone",
},
rows: [
{ id: 1, name: "Test Name 1", phone: "587-917-1241" },
{ id: 2, name: "Test Name 2", phone: "250-682-3553" },
{ id: 3, name: "Test Name 3", phone: "707-848-0782" },
],
},
});
And my CSS
table {
text-align: left;
font-family: "Open Sans", sans-serif;
width: 500px;
border-collapse: collapse;
border: 2px solid #444777;
margin: 10px;
}
table th {
background: #444777;
color: #fff;
padding: 5px;
min-width: 30px;
}
table td {
padding: 5px;
border-right: 2px solid #444777;
}
table tbody tr:nth-child(2n) {
background: #d4d8f9;
}
I want to mount the Vue app instance to a div container and use v-for directive to iterate through the columns and rows array to generate the table header
and body, what should I do?
I used this vue version<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
expected outcome:
ID Full Name Phone
1 Test Name 1 587-917-1241
2 Test Name 2 250-682-3553
3 Test Name 3 707-848-0782
4
Answers
You can write your template string in js like this:
You can write like this
Here is an example to mount Vue app in a HTML element-
You are almost there, Just have a look into this
List Rendering
documentation.Live Demo :