I have this html file that fetches data from an API and renders this into a table, it works successfully from there.
I'm trying to convert the html file over to vue but I'm having some issues, although vue can fetch the data from the API it's not showing the table at all on the webpage (eventhough I've exported the JSONTable.vue and imported it to App.vue so App.vue can access the JSONTable.vue page)
From my html files I used these two external sources which draws the table successfully:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
But I replaced it with this inside the tag because vue was throwing template errors, it fixes the template issues:
import JQuery from 'jquery'
let $ = JQuery
How do I use the external stylesheet and script from above in vue and allow it for me to get rid of 'import JQuery' (because if I remove import JQuery it will say $ is not defined)?
My vue site:
<template>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <!-- styling the table with an external css file -->
<body>
<div class="container">
<div class="table-responsive">
<h1>JSON data to HTML table</h1>
<br />
<table class="table table-bordered table-striped" id="tracerouteTable">
<tr>
<th>id</th>
<th>name</th>
<th>salary</th>
<th>age</th>
<th>image</th>
</tr>
</table>
</div>
</div>
</body>
</head>
</template>
<script>
export default {
name: 'JSONTable'
}
import JQuery from 'jquery'
let $ = JQuery
$(document).ready(function(){
$.getJSON("http://dummy.restapiexample.com/api/v1/employees", function(data){
var employeeData = '';
console.log(data);
$.each(data, function(key, value){
employeeData += '<tr>';
employeeData += '<td>'+value.id+'</td>';
employeeData += '<td>'+value.employee_name+'</td>';
employeeData += '<td>'+value.employee_salary+'</td>';
employeeData += '<td>'+value.employee_age+'</td>';
employeeData += '<td>'+value.profile_image+'</td>';
employeeData += '<tr>';
});
$('#tracerouteTable').append(employeeData);
});
});
</script>