I'm new to VueJS, so this is probably a very simple problem, but here goes.
I'm making a call to my API to get a set of records. I want to display those records in a simple table, but then I want to be able to click a link in the last cell of the row and be sent to a new URL -- a url for the detail of that object.
Here's what I have so far:
Vue Stuff:
var vm = new Vue({
el: '#league-table',
data: {
leagues: [],
apilink: '/api/leagues/',
},
mounted: function() {
this.getLeagues();
},
methods: {
getLeagues: function() {
var self = this
$.get('/api/leagues/', function(data){
$.each(data, function(index, obj) {
self.leagues.push(obj)
});
});
},
sayConsole: function() {
console.log("OUTPUT here....")
}
}
});
HTML Stuff:
<div class='card__content'>
<div id='league-table' class='table-responsive'>
<table class='table table--lg team-roster-table table-hover'>
<thead>
<th class='team-roster-table__name'>ID</th>
<th class='team-roster-table__name'>Name</th>
<th class='team-roster-table__name'>Characters</th>
<th></th>
</thead>
<tbody>
<tr v-for='league in leagues'>
<td class='team-roster-table__number'>{{ league.id }}</td>
<td class='team-roster-table__name'>{{ league.name }}</td>
<td class='team-roster-table__name'>{{ league.max_players }}</td>
<td class='team-roster-table__name'>
<a v-on:click='sayConsole'>{{ league.id }}</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
When I open the page, the table is presented properly, and all the data is loaded correctly. However, it's the clicking of the link in the last cell that isn't working. I believe I have some sort of scope issue -- something about how the row doesn't have a method sayConsole
, but I'm not too sure (that's what I can determine from the day of researching the issue).
Ideally, I want to have a URL that takes me to a detail page for that object.