I am currently working on an API request that involves calling a SQL query within the function. I want to pass the results to a .vue page utilizing express-vue. Below is the code snippet for the API request:
router.get('/search', (req, res, next) => {
var keyword = ("%" + req.query.keyword + "%")
var lat = req.query.lat
var lng = req.query.lng
console.log(keyword, lat, lng)
connection.query('SELECT *, ( 3959 * acos (cos ( radians(?) )* cos( radians( lat ) )* cos( radians( lng ) - radians(?) )+ sin ( radians(?) )* sin( radians( lat ) ))) AS distance FROM job_posting where job_title like ? HAVING distance < 25', [
lat, lng, lat, keyword
], function(err, rows) {
})
res.render('main', {
// data: {
// results
// },
vue: {
meta: {
title: 'Page Title',
},
components: ['myheader', 'myfooter', 'searchform', , 'results']
}
});
})
Now, let's take a look at the Main.vue page:
<template>
<div id="wrap">
<div class="col-md-1"></div>
<div id="main-container" class="container col-md-10">
<myheader></myheader>
<div class="col-md-4"></div>
<div class="col-md-4">
<searchform></searchform>
<results></results>
</div>
<div class="col-md-4 text-center">
</div>
<div class="col-md-1"></div>
</div>
</div>
</template>
I am aiming to pass the retrieved "rows" data to the results.vue component. Here is how the data looks coming from the database:
[ RowDataPacket {
id: 1,
job_title: 'Software Engineer',
job_desc: '<p>Ayo</p>',
location: 'Akron, OH',
job_type: 'Full-Time',
salary: '',
date_created: 2016-11-23T05:00:00.000Z,
short_desc: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e07071107113e19131f1712501d1113">[email protected]</a>',
apply_url: 'Ayo',
lat: '41.084821',
lng: '-81.515607',
distance: 0 },
RowDataPacket {
id: 2,
job_title: 'Software Engineer',
job_desc: '<p>Ayo</p>',
location: 'Akron, OH',
job_type: 'Full-Time',
salary: '',
date_created: 2016-11-23T05:00:00.000Z,
short_desc: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6afafb9afb996b1bbb7bfbaf8b5b9bb">[email protected]</a>',
apply_url: 'Ayo',
lat: '41.084821',
lng: '-81.515607',
distance: 0 },
RowDataPacket {
id: 3,
job_title: 'Software Engineer',
job_desc: '<p>Ayo</p>',
location: 'Akron, OH',
job_type: 'Full-Time',
salary: '',
date_created: 2016-11-23T05:00:00.000Z,
short_desc: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6dfdfc9dfc9e6c1cbc7cfca88c5c9cb">[email protected]</a>',
apply_url: 'Ayo',
lat: '41.084821',
lng: '-81.515607',
distance: 0 } ]