I am using SharePoint Online and Vuejs.
I am trying to display a table and in each cell there will be a function call with 2 arguments passed to a method to filter an axios call to a list. When I have the call in one cell it works fine but when I add the call to a different cell with different arguments, my code goes into an infinite loop. I can tell from my developer tool as I see the numbers flashing in the console and on the page. It seems like it calls the method several times for some odd reason and I'm not even using any kind of loop. Here's the code:
Vue.component('msr-table', {
template:
`
<table>
<tr>
<th>LCAT</th>
<th>Position 1</th>
<th>Position 2</th>
<th>Position 3</th>
<th>Position 4</th>
<th>Position 5</th>
<th>Position 6</th>
<th>Position 7</th>
<th>Position 8</th>
<th>Position 9</th>
</tr>
<tr>
<td>Operations Research Analyst</td>
<td>{{ getMsrInputData('Position 1', 'Operations Research Analyst') }}</td>
<td>{{ getMsrInputData('Position 2', 'Operations Research Analyst') }}</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Research Analyst</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
`,
method: {
getMsrInputData: function(lName,lCat){
endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbyTitle('Track List')/items?$select=Lists&$filter=substringof('"+ lName +"',%20Lists)%20and%20(mCAT%20eq '"+ mCat +"')";
var vm = this;
axios.get(endPointUrl).then(function(response){
vm.num = response.data.value.length;
console.log(vm.num);
}).catch(function(error){
console.log(error)
});
return this.num;
},
}
})
I've done everything but I just can't figure out why. Any ideas/help would be much appreciated. Thanks!
I just need a single value returned where ever I make a call.