Content isn't displayed unless commented and then uncommented - vue.js

I am working with an expansion panel that makes an API call when clicked, populating the v-card and v-layout with the response data. The challenge I am facing is that initially, the v-layout isn't populated.
If I comment out the v-flex elements, the v-layout will generate and display the expected number of rows (that are now empty and blank). Then, I uncomment the v-flex which displays the data properly within the v-layout.
Below is the template code I am using, alongside the API call that is being used when the v-expansion-panel-content is clicked:
<v-expansion-panel expand>
<v-expansion-panel-content v-for="(device, index) in devices" :key="index">
<div slot="header" #click="requestDeviceBreadcrumbs(device.id);">
<v-card flat>
<v-layout row wrap class="pa-3 project" :class="inAlarm(device)">
<v-flex xs12 md6>
<div class="caption grey--text">Location</div>
<div>{{ device.location }}</div>
</v-flex>
<v-flex xs6 sm4 md2>
<div class="caption grey--text">Address</div>
<div>{{ device.ip_address }}:{{ device.http_port_number }}</div>
</v-flex>
<v-flex xs6 sm4 md2>
<div class="caption grey--text">Manufacturer</div>
<div>{{ device.manufacturer }}</div>
</v-flex>
<v-flex xs2 sm4 md2>
<div class="right">
<v-chip small class="white--text caption my-2" :class="inAlarm(device)">
{{ device.alarm_count }}
</v-chip>
</div>
</v-flex>
</v-layout>
</v-card>
</div>
<v-card flat>
<v-layout row wrap class="pa-3 project" v-for="(breadcrumb, index) in device.breadcrumbs" :key="index" >
<v-flex xs12 md6>
<div class="caption grey--text">Oid</div>
<div>{{ breadcrumb.oid }}</div>
</v-flex>
<v-flex xs6 sm4 md3>
<div class="caption grey--text">Value</div>
<div>{{ breadcrumb.value }}</div>
</v-flex>
<v-flex xs6 sm4 md3>
<div class="caption grey--text">Timestamp</div>
<div>{{ breadcrumb.timestamp }}</div>
</v-flex>
</v-layout>
<v-divider></v-divider>
</v-card>
</v-expansion-panel-content>
</v-expansion-panel>
And my API request function:
requestDeviceBreadcrumbs: function(device_id) {
axios({
method: "get",
url: `http://127.0.0.1:8000/api/v1/breadcrumbs/?device=${device_id}`
}).then(response => {
this.devices.find(obj => obj.id === device_id).breadcrumbs =
response.data;
});
}
My concern is that it's taking too long for the API to respond, is this the case? If so, what is acceptable way of handling this scenario?
Thank you.

Use Vue.set to add/update a reactive property to one device:
requestDeviceBreadcrumbs: function(device_id) {
axios({
method: "get",
url: `http://127.0.0.1:8000/api/v1/breadcrumbs/?device=${device_id}`
}).then(response => {
let device = this.devices.find(obj => obj.id === device_id)
this.$set(device, 'breacrumbs', response.data)
});
}

Related

Why parameter returns 'undefined' when using Vuetify

I'm starting to use vuetify along with a 'payment gateway' that I'm learning, but I've had a little problem.
If I have a form like this:
<form #submit.prevent="continuar" id="customer-form">
<div class="card-errors"></div>
<div class="form-group">
<label>Nombre del usuario de tarjeta</label>
<input type="text" data-epayco="card[name]">
</div>
<div class="form-group">
<label>Email</label>
<input type="text" data-epayco="card[email]">
</div>
...
<button type="submit">¡Pagar ahora!</button>
</form>
The "Token" parameter returns a value that is not undefined.
continuar(event){
ePayco.token.create(event.target, (error, token) => {
if(!error) {
console.log("token: " + token)
} else {
console.log(error)
}
})
},
But when I use vuetify the "Token" parameter returns "undefined" even when the "Epayco" library shows a message that everything has happened correctly.
<form id="customer-form" #submit.prevent="continuar">
<div class="card-errors"></div>
<v-layout row align-center>
<v-flex md3 offset-md1 class="mr-3">
<v-layout justify-end>
<span>Nombre en la tarjeta*</span>
</v-layout>
</v-flex>
<v-flex md4>
<v-text-field data-epayco="card[name]"/>
</v-flex>
</v-layout>
<v-layout row align-center>
<v-flex md3 offset-md1 class="mr-3">
<v-layout justify-end>
<span>Email</span>
</v-layout>
</v-flex>
<v-flex md4>
<v-text-field data-epayco="card[email]"/>
</v-flex>
</v-layout>
......
<v-layout class="my-3" justify-center>
<v-btn type="submit">Pagar</v-btn>
</v-layout>
</form>
Does anyone know why the problem?
It should be noted that when an error occurs the parameter 'error' returns the error and not undefined
According to the example here it appears you should be using the ePayco.token.create() function a bit differently.
epayco.token.create(paymentDetails)
.then(function(token) {
console.log(token);
})
.catch(function(err) {
console.log("err: " + err);
});

Vuetify V-flex full only half of card

My v-flex it is not respecting my orders and only half of element it was rendered. see the print:
Print from my view
Here is my script:
<v-card-title primary-title>
<div>
<p class="subheading grey--text">My title</p>
<h3 class="headline my-4">my sub title</h3>
<div>
<v-container fluid>
<v-card flat v-for="ticket in tickets" :key="ticket.id">
<v-layout row wrap :class="`pa-2 ticket ${ticket.status.id}`">
<v-flex xs3>
<div class="caption grey--text">#ID</div>
<div>{{ticket.id}}</div>
</v-flex>
<v-flex xs3>
<div class="caption grey--text">Assunto</div>
<div>{{ticket.subject}}</div>
</v-flex>
<v-flex xs3>
<div class="caption grey--text">Criado em</div>
<div>{{ticket.created_on}}</div>
</v-flex>
<v-flex xs3>
<div class="right">
<v-chip
small
:class="`${ticket.status.id} white--text caption my-2`"
>{{ticket.status.name}}</v-chip>
</div>
</v-flex>
</v-layout>
</v-card>
</v-container>
</div>
</div>
</v-card-title>
Someone has any ideas?
Tks.
You can add a full width flex box above the v-card on line 7:
<v-flex xs12>
<v-card flat v-for="ticket in tickets" :key="ticket.id">
...
EDIT: My mistake... after taking another look you can change the div on line 2 to a v-flex, which will give you the results like in this codepen: https://codepen.io/retrograde/pen/ZNYJRq?editors=0001 Note that I removed the code added by my original answer.

v-for in vue update all object in array although the key has been determined

this my code :
<v-container grid-list-md fluid-fix>
<div v-for="(data ,c) in chapter.data" :key="c" class="my-3" style="border: 1px solid;">
<v-layout row wrap px-3>
<v-flex xs12 sm1>
<v-text-field v-model="data.num" label="Chapter"></v-text-field>
</v-flex>
<v-flex xs12 sm3>
<v-text-field v-model="data.name" label="name"></v-text-field>
</v-flex>
<v-flex xs12 sm8 d-flex>
<v-text-field v-model="data.description" label="short info" style="width: 100%;"></v-text-field>
<div>
<v-btn class="d-inline-flex servers--btn" color="success" #click="addServer(c)">add server</v-btn>
</div>
</v-flex>
</v-layout>
<v-container grid-list-md fluid-fix>
<v-layout wrap v-for="(server ,s) in data.servers" :key="s">
<v-flex sm12>
<div class="d-inline-flex">
<v-autocomplete
:items="data.serverlist"
v-model="server.server_id"
#input="serverChange(data)"
label="Server"
></v-autocomplete>
</div>
<div class="d-inline-flex text-xs-right pr-1">
<v-btn color="orange" class="white--text servers--btn" #click="demo_edit(c,s,server.links)">demo and Edit</v-btn>
</div>
<div class="d-inline-flex text-xs-right pr-1" style="float: right;">
<v-btn color="red" class="white--text servers--btn" #click="delSvOnChap(c,s)">Delete Server</v-btn>
</div>
</v-flex>
<v-flex sm12>
<v-textarea
v-model="server.links"
label="box image"
></v-textarea>
</v-flex>
</v-layout>
</v-container>
serverChange(data){
data.serverlist.forEach(obj => {
if(_.find(data.servers,{server_id: obj.value})){
obj.disabled = true
}else{
obj.disabled = false
}
});
},
serverChange is in methods
i want update disabled in the key has been determined , but it's update all object in array
when I log serverChange function i just see one object return and that's what I'm looking forward to but when i set disabled for this object , vue update all object in array
I need a solution for this problem .

Understanding the Stucture of a Vue Project (vuetify)

I'm new to Vue and Vuetify, I'm just trying to figure out the structure I should have when writing my code. I'm starting to get a bit confused with the differences between v-layout and v-flex.
Here is my current structure: I'm trying to position the flex xs8 (with the room type) next to the flex xs2 (with paragraph 'test').
<v-container ma-6 grid-list-xl>
<v-layout>
<v-flex md8 xs12>
<!-- My spaces -->
<v-layout v-for="space in spaces" v-if="space.id === selected" :key="space.id" row wrap>
<!-- The rooms -->
<v-flex v-for="room in space.rooms" :key="room.id" xs12 md6>
<!-- A room -->
<v-card class="card-round">
<!-- Image -->
<v-carousel>
<v-carousel-item v-for="image in room.images" :src="image.src" :key="image.id"></v-carousel-item>
</v-carousel>
<!-- Information -->
<v-layout row wrap>
<v-card-text primary-title>
<v-flex xs8>
<p> {{ room.type }} </p>
<h3 class="headline"> {{ room.name }} </h3>
</v-flex>
<v-flex xs2>
<p>test</p>
</v-flex>
</v-card-text>
</v-layout>
</v-card>
</v-flex>
</v-layout>
</v-flex>
<v-flex hidden-md-and-down>
<p>temp sidebar</p>
</v-flex>
</v-layout>
</v-container>
If you want any elements to be displayed side by side (inline), put them inside v-layout
<v-layout>
<v-flex xs8>
<p> {{ room.type }} </p>
<h3 class="headline"> {{ room.name }} </h3>
</v-flex>
<v-flex xs2>
<p>test</p>
</v-flex>
</v-layout>
The <v-layout> tag component just represent the flex box (basically, a div with a display: flex; CSS rule).
The <v-flex> tags components that you put inside the <v-layout> tag are the elements of your flexbox (the ones that you can customize the "grow/shrink behavior" with the flex CSS rule)
That's it.

vue.js how to toggle html tag display on mousehover

I can currentl toggle the display of a paragraph on mouseover event , but how to come back to the initial paragraph when mousehover ends.. ?
HTML
<div id="app">
<v-app id="inspire">
<v-container fluid grid-list-sm>
<v-layout row wrap justify-space-around>
<v-flex d-flex xs12 sm3 md3>
<v-card class="flexcard" color="white" tile flat>
<v-card-title class="layout justify-center">
<div class="headline mt-1 mb-1 display-1 text-xs-center">MEMBERSHIP FEES</div>
</v-card-title>
<v-card-text class="grow">
<v-layout row justify-space-between align-baseline>
<v-flex xs2>
<v-btn v-on:mouseover="toggleInfo" dark small round color="green">2018</v-btn>
</v-flex>
<v-flex xs9 style="text-align: left;">
<p v-if="!displayInfo">PAID</p>
<p v-else>10.00$ - February, 22nd - Bank Transfer</p>
</v-flex>
</v-layout>
</v-card>
</v-card>
</v-flex>
</v-layout>
</v-container>
</v-app>
</div>
JS SCRIPT
new Vue({
el: '#app',
data () {
return {
displayInfo: false
}
},
methods: {
toggleInfo () {
this.displayInfo = !this.displayInfo
}
}
})
see pen.io test
You are toggling the displayInfo on mouseover, now you will also have to toggle it on mouseleave.
<v-btn v-on:mouseover="toggleInfo" v-on:mouseleave="toggleInfo" dark small round color="green">2018</v-btn>