I have retrieved some data from MySQL and I am looking to integrate it into a vue.js data property for seamless iteration using v-for.
What is the ideal format to use (JSON or array) and how can I ensure that the data is properly accessible in vue.js?
<?php
$sql = 'SELECT * FROM courses;';
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if($resultCheck > 0) {
$coursesArray = array();
while ($row = mysqli_fetch_assoc($result)) {
$courseObj = new stdClass();
$courseObj->date = $row['date'];
$courseObj->startTime = $row['start_time'];
$courseObj->endTime = $row['end_time'];
$courseObj->availableSeats = $row['seats'];
array_push($coursesArray, $courseObj);
}
echo json_encode($coursesArray);
}
?>
...
<script>
var app4 = new Vue({
el: '#app-4',
data: {
courses: <?php echo $coursesArray; ?>
},
delimiters: ["((","))"],
methods: {
flipstate:function(){
console.log('flipped');
}
},
})</script>