I'm writing this code where a Vue.JS module calls a PHP file that fetches data from an external server and returns a JSON response. I had written a loop for getting a particular field from JSON and print them in a conversation format. But it displays only empty message bubbles with no text (The number of message bubbles is correct but no text inside it).
Here's my code:
const app = new Vue({
el: "#chatview",
data: {
data:[],
txtInput: '',
mid:0
},
methods:
{
GetBubbleType: function (name){
if(name === "Support")
return "yours messages";
else
return "mine messages";
},
},
mounted(){
axios.post(
'./ConversationGetter.php',
{
function2call: 'getRecord',
id: 1,
}
)
.then(response => {this.data=response.data.data;
console.log(response.data);
})
.catch(error => {});
},
template: `
<div style ="font-family:Open Sans;font-size:16px">
<div v-for="message in data">
<div class="fade-in">
<div v-bind:class="GetBubbleType(data.name)">
<div class="message last">
<p>{{data.message}}</p>
</div>
</div></div></div> `
})
The response returned from PHP:
{
"data": [
{
"Modified_Time": "2019-12-13T16:08:36+05:30",
"$currency_symbol": "$",
"Message": "Hey!",
"Created_Time": "2019-12-13T16:08:36+05:30",
"Name": "Me",
},
{
"Modified_Time": "2019-12-13T16:08:27+05:30",
"$currency_symbol": "$",
"Message": "Yo!",
"Created_Time": "2019-12-13T16:08:27+05:30",
"Name": "Me",
},
],
}
data.namebut it should bedata.Name- case is significant in javascript - you also have"message in data"then usedata.name... so it actually should beGetBubbleType(message.Name)response.data.data? Or is thatresponse.data?