link1507 link1508 link1509 link1510 link1511 link1512 link1513 link1514 link1515 link1516 link1517 link1518 link1519 link1520 link1521 link1522 link1523 link1524 link1525 link1526 link1527 link1528 link1529 link1530 link1531 link1532 link1533 link1534 link1535 link1536 link1537 link1538 link1539 link1540 link1541 link1542 link1543 link1544 link1545 link1546 link1547 link1548 link1549 link1550 link1551 link1552 link1553 link1554 link1555 link1556 link1557 link1558 link1559 link1560 link1561 link1562 link1563 link1564 link1565 link1566 link1567 link1568 link1569 link1570 link1571 link1572 link1573 link1574 link1575 link1576 link1577 link1578 link1579 link1580 link1581 link1582 link1583 link1584 link1585 link1586 link1587 link1588 link1589 link1590 link1591 link1592 link1593 link1594 link1595 link1596 link1597 link1598 link1599 link1600 link1601 link1602 link1603 link1604 link1605 link1606 link1607 link1608 link1609 link1610 link1611 link1612 link1613 link1614 link1615 link1616 link1617 link1618 link1619 link1620 link1621 link1622 link1623 link1624 link1625 link1626 link1627 link1628 link1629 link1630 link1631 link1632 link1633 link1634 link1635 link1636 link1637 link1638 link1639 link1640 link1641 link1642 link1643

[Vue.js] How to recursively fetch collection with all subcollections? Subscribe to RSS

there is a collection in firestore called ‘steps’ and inside steps collection there is lots of documents and subcollections called ‘substeps’ in each steps document. I need to create array which will have all the steps and substeps inside that I could use this component, so the array should look like this

let steps = [
{
step: 1,
id: ‘1’
substeps: [
{
step: ‘1.1’
substeps: [
{
step: ‘1.1.2’
}
]
}
]
}
]

Now to crate recursive functions with will fetch all the substeps if they are exists

I tried to create function which should fetch all the subcollections, but I don’t know how to finish it, so below example of what I tried, but notice function not finished and it is only first steps
Here is documentation

fetchAllStepsDeep (request) {
//this.steps = array of objects with step data
let result = []
let requestLocal = this.$firebaseFirestore.collection(‘steps_for_classes’)

for (let i in this.steps) {
result.push(this.steps[i])
requestLocal.doc(this.steps[i].id).get().then((doc) => {
if (doc.exists) {
console.log(‘Document data:’, doc.data())
} else {
// doc.data() will be undefined in this case
console.log(‘No such document!’)
}
}).catch((error) => {
console.log(‘Error getting document:’, error)
})
}
}

Can someone help me to retrieve all the subcollections inside collection and create one big array with other child arrays of objects? I use vue.js framework, so maybe this can be helpful

Thanks

Solution :

If the subcollection is always called substeps, you can create a helper function to handle the recursion

function getSubstepsOf(docRef, path, result) {
docRef.collection(“substeps”).get((querySnapshot) => {
querySnapshot.forEach((doc) => {
result.push({ path, doc });
getSubstepsOf(doc.ref, `${path}/substeps/${doc.id}`, result);
});
});
}

And then call it with this from the existing code:

getSubstepsOf(doc.ref, doc.id, result);

[Vue.js] Binding Data On Image Src Not Working Properly Subscribe to RSS

When I select images I change them to base64 and save them inside array inside an object. to show them via v-bind:src but they don’t.

<script>
export default {
data (){
return {
product:{
name:’’,
description:’’,
Photo:[]
}
}
},
methods:{
PhotoSelected (e){
Here I change photos to base64
}
}
</script>

Solution :

there is been through a similar problem related to base64 image rendering.

You need to append data:image/jpg;base64, before the converted image bytes.

<img v-bind:src=”‘data:image/jpeg;base64,’+{converted image}” />

If this doesn’t resolve the problem, please update the question with a reproducible example

[Vue.js] How to track page views with google Tag Manager for a single page app? Subscribe to RSS

there is built a single page app using vue.js when trying to track users on my site using google tag manager. there is it up and running but its not tracking page changes. I set it up google tag manager as below.

there is tried a couple of different variables but when just randomly guessing at this point.
Current Setup
As you can see from the images there is tag setup and triggered by Page view and History change. setting the {page URL} field to {New History Fragment}

My URLS look something like

http://website.com/#/section1/page1
which changes to
http://website.com/#/section2/page1
etc….

I need to be able to track these changes but analytics only thinks one page was visited. “ / “

Any ideas would be appreciated.

Solution :

Welcome to Stackoverflow!

I hate to be “that guy”, but have you considered using the vue-analytics library? there is used it in a pet project with success (only the basic functionality though). You can check it out here: https://github.com/MatteoGabriele/vue-analytics

[Vue.js] Unable to see my front-end but npm successfully build Subscribe to RSS

My public/app.jsstrong textwhen creating a single forum app and when I try to run it on chrome following message occurs

[Error says app.js:61722 [vue.js warn]: Failed to mount component:
template or render function not defined.

found in

-–> <AppHome>
<Root>

My app.js file

Solution :

If you have something like component: require(‘../components/blabla.vue’), try adding a .default to be correctly rendered. It will look like this:

component: require(‘../components/blabla.vue’).default

[Vue.js] Prevent submission form Data when enter on search Subscribe to RSS

there is form.inside this form component there is a search box.i created two methods one is for search other one is for submit data. every time I enter on search both methods are fires.

I used this @submit.prevent=”saveFormData” for entire form and v-on:submit.prevent keyup.enter =”searchCustomerRecord” for search record
then the searchCustomerRecords not working at all

<form class=”mx-auto w-full max-w-lg” @submit.prevent=”saveFormData”>
….
<div class=”sm:text-left my-2 md:text-right”>
<input type=”search” class=”w-full bg-purple-white”placeholder=”Search Here…”
name=”search” v-model=”searchInput” v-on:keyup.enter =”searchCustomerRecord”>
</div>
…..

<div class=”flex-auto text-center px-3 mb-6 md:mb-0”>
<button type=”submit” class=”m-2 py-2 hover:bg-green-dark “>Save</button>
<button class=”m-2 py-2 hover:bg-red”>Clear</button>
</div>
</form>

Solution :

You can just catch the event earlier inside input and stop its propagation, like:

<input type=”search” @keydown.enter.prevent.stop=”searchCustomerRecord” />

[Vue.js] HTML table initialized with Vue.js how to alternate row color Subscribe to RSS

I’m a beginner in Vue.js. there is a Vue.js script that stores some data in order to put it in a table. I can manage put it in the table, but I can’t figure out how to alternate the color in the rows of the table (I just have to put a ‘class=”table-light”‘ in the ).

I tried doing something like “var i = 0;” and then I wanted to do something like : if(i % 2 == 0) { print ‘’; } else { … }
But that doesn’t work so far because I don’t think there’s any function to print something, and I can’t even get my variable to increment.
If anyone could help me figure this out…

//Where I store the data
var demo = new Vue({
el: ‘#demo’,
data: {
searchQuery: ‘’,
gridColumns: [‘nom’, ‘description’, ‘url’],
gridData: [
{ nom: ‘test’, description: ‘test’, url: ‘test’ },
{ nom: ‘test’, description: ‘test’, url: ‘test’ },
{ nom: ‘test’, description: ‘test’, url: ‘test’ }
]
}
})

<script type=”text/x-template” id=”grid-template”>

var i = 0;

<table class=”table table-hover”>
<thead>
<tr class=”table-title”>
<th v-for=”key in columns”
@click=”sortBy(key)”
:class=”{ active: sortKey == key }”>
{ key | capitalize }
<span class=”arrow” :class=”sortOrders[key] > 0 ? ‘asc’ : ‘dsc’”>
</span>
</th>
</tr>
</thead>

<tbody>

<template v-for=”entry in filteredHeroes”>
//—————————————————————–
//Where I’m supposed to add class=”table-light”

<tr>
//—————————————————————–

<th scope=”row”> {entry[‘nom’]} </th>
<td> {entry[‘description’]} </td>
<td>{entry[‘url’]} <a v-bind:href=”entry[‘url’]“ class=”ni ni-curved-next pull-right”></a></td>
</tr>
</template>
</tbody>
</table>
</script>

Solution :

Add an index to the v-for

<template v-for=”(entry, index) in filteredHeroes”>
<tr :class=”{‘table-light’: index % 2}”>

[Vue.js] Close previous table row when clicking on another table row Subscribe to RSS

I’m fetching data into the table and on clicking any table row it open a nested colspan inside table row. to close previous table row if i click on another table row (Like accordion does )

this is a table body structure

<tbody style=”cursor:pointer” v-for=”(statement,index) in statements”>
<tr @click=”statementDetail(index,statement.paper_quality_id.id,statement.paper_brand_id.id,statement.paper_size_id.id,statement.thickness)”
\>
<td>{index+1}</td>
<td>
{statement.paper_quality_id.paper_quality} -
{statement.paper_size_id.length} X {statement.paper_size_id.width} -
{statement.paper_brand_id.paper_brand} -
{statement.thickness}
</td>
<td>
<div class=”row”>
<div
class=”col-md-4 text-center”
\>{parseInt((statement.in_total_before - statement.total_out_before)/500)}</div>
<div
class=”col-md-4 text-center”
\>{parseInt((statement.in_total_before - statement.total_out_before)%500)}</div>
</div>
</td>
<td>
<div class=”row”>
<div
class=”col-md-4 text-center”
\>{parseInt((statement.total_sheets_in_range)/500)}</div>
<div
class=”col-md-4 text-center”
\>{parseInt((statement.total_sheets_in_range)%500)}</div>
</div>
</td>
<td>
<div class=”row”>
<div
class=”col-md-4 text-center”
\>{parseInt((statement.total_outward_range)/500)}</div>
<div
class=”col-md-4 text-center”
\>{parseInt((statement.total_outward_range)%500)}</div>
</div>
</td>
<td>
<div class=”row”>
<div class=”col-md-4 text-center”>
{
parseInt((((statement.in_total_before - statement.total_out_before) + (statement.total_sheets_in_range)) - statement.total_outward_range)/500)
}
</div>
<div class=”col-md-4 text-center”>
{
parseInt((((statement.in_total_before - statement.total_out_before) + (statement.total_sheets_in_range)) - statement.total_outward_range)%500)
}
</div>
</div>
</td>
</tr>

This the nested table it appears when we click on table row

<tr :id=”‘show_‘+index” v-if = “index = indexData” >
<td colspan=”6”>
<table class=”table table-hover”>
<tr>
<th>Date</th>
<th>Opening</th>
<th>Inward</th>
<th>Outward</th>
<th>Balance</th>
</tr>
<tr v-for=”(_statement,index) in statements_details” >
<td>{_statement.date}</td>
<td>
<div class=”row”>
<div
class=”col-md-3 text-center”
\>{parseInt((_statement.opening.total_in - _statement.opening.total_out)/500)}</div>
<div
class=”col-md-3 text-center”
\>{parseInt((_statement.opening.total_in - _statement.opening.total_out)%500)}</div>
</div>
</td>
<td>
<div class=”row”>
<div class=”col-md-3 text-center”>{parseInt((_statement.inward)/500)}</div>
<div class=”col-md-3 text-center”>{parseInt((_statement.inward)%500)}</div>
</div>
</td>
<td>
<div class=”row”>
<div class=”col-md-3 text-center”>{parseInt((_statement.outward)/500)}</div>
<div class=”col-md-3 text-center”>{parseInt((_statement.outward)%500)}</div>
</div>
</td>
<td>
<div class=”row”>
<div
class=”col-md-3 text-center”
\>{parseInt((_statement.balance.total_in - _statement.balance.total_out)/500)}</div>
<div
class=”col-md-3 text-center”
\>{parseInt((_statement.balance.total_in - _statement.balance.total_out)%500)}</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>

This is my js file

export default {
data() {
return {
statements: ‘’,
users: [],
ledger_name: ‘’,
paper_details: ‘’,
account_list: false,
//statement Objects
id: ‘’,
start_date: ‘’,
end_date: ‘’,
paper_quality_id: ‘’,
paper_size_id: ‘’,
paper_brand_id: ‘’,
thickness: ‘’,
statements_details: ‘’,
stockIDS: ‘’,
indexData: ‘’
};
},
created() {
this.fetchData();
},
components: {
appInventoryNavigation: InventoryNavBar,
},
methods: {

// Fetching Ledger Account List
fetchData() {
var vm = this;
axios.get(‘/ledger/‘)
.then((response) => {
console.log(response)
vm.users = response.data
}).catch((err) => {
console.log(err)
});
},
//Setting LedgerID In Hidden Input Field
setLedgerID_1(id, name) {

this.account_name = id;
this.account_list = false;
this.id = id;
this.ledger_name = name;
},
call() {
this.account_list = true;
},
//Posting LedgeID
PostLedgerID(e) {
e.preventDefault();

const AccountDetail = {
id: this.id,
start_date: this.start_date + ‘ 00:00:00.957761’,
end_date: this.end_date + ‘ 00:00:00.957761’
}
var vm = this;
axios.post(‘/Statement/‘, AccountDetail)
.then((response) => {
console.log(response)
vm.statements = response.data;

}).catch((err) => {
console.log(err)
});
},

//Show Hide Nested Table
statementDetail(rowid, paper_id, brand_id, size_id, thickness) {
this.indexData = rowid;
alert(this.indexData)
const userDetail = {
account_access_key_id: $(‘#ledger_id’).val(),
start_date: this.start_date + ‘ 00:00:00.957761’,
end_date: this.end_date + ‘ 00:00:00.957761’,
paper_quality_id: paper_id,
paper_brand_id: brand_id,
paper_size_id: size_id,
thickness: thickness
}
axios.post(‘/StatementDetail/‘, userDetail)
.then((response) => {

$(‘#show_‘ + rowid).toggle();
this.statements_details = response.data;
}).catch((err) => {
console.log(err)
});
}

},
};

Solution :

Change v-show=”indexData === index”.

And in the method check if rowid is changed and move this.indexData = rowid; after axios request:

statementDetail(rowid, paper_id, brand_id, size_id, thickness) {
if (rowid !== this.indexData){
const userDetail = {
account_access_key_id: $(‘#ledger_id’).val(),
start_date: this.start_date + ‘ 00:00:00.957761’,
end_date: this.end_date + ‘ 00:00:00.957761’,
paper_quality_id: paper_id,
paper_brand_id: brand_id,
paper_size_id: size_id,
thickness: thickness
}
axios.post(‘/StatementDetail/‘, userDetail)
.then((response) => {

$(‘#show_‘ + rowid).toggle();
this.statements_details = response.data;
}).catch((err) => {
console.log(err)
});
this.indexData = rowid;
}
}

Good luck.

[Vue.js] Passed data inside event is not reactive Subscribe to RSS

Have no errors, just do not work. Addition of this has no affecting too.

input( type=”number” v-model=”myData” @wheel=”wheelIt($event, myData, myMethod)” )

methods:
{
wheelIt ( event, data, func )
{
if ( event.deltaY < 0 )
{
data += 1
func()
event.preventDefault()
}
if ( event.deltaY > 0 )
{
data -= 1
func()
event.preventDefault()
}
},

Hardcoded wheel event works just fine, but I need parameterise it.

Solution :

Solution is not increment inside function, but in event directly

@wheel=”wheelIt($event, myData += 1, myMethod)”

[Vue.js] Question about parent/child relationships and components Subscribe to RSS

I’m currently trying to port a project from vuex/REST to vue-apollo. The project shows a list of events, and each event can be expanded to show details, including attendees.

So I’m having an EventList component, that fetches the events and all attributes necessary for the list. And there is a EventDetails child component that is expanded from the list onclick. EventDetails requires some event data as well as the list of attendees to render. Problem is, I cannot find an elegant way to build the queries.

Currently, there is one query for events, that is executed by the EventList component:

query Events($type: [String!]) {
events(type: $type) {
id
name
attendeeCount
}
}

Inside the EventList component, I’m passing the event ID to the EventDetails child component, which then in turn queries the API for attendees:

query Event($id: ID!) {
event(id: $id) {
id
name
attendeeCount
attendees {
id
name
paymentState
}
}
}

The parent component (simplified):

<template>
<EventDetails v-for=”event in events” :eventId=”event.id” />
</template>

<script lang=”ts”>
import

@Component({
apollo: {
events: { }
},
components: {
EventsDetails
}
})
export default class EventList extends vue.js {
events: Event[] = []
}
</script>

The child component (simplified):

export default class EventDetails extends vue.js {
@Prop(Number) eventId!: ID
// I’d like to pass in the complete event object here, and just
// fetch another attribute “attendees” via graphql, like this:
@Prop(Object) event!: Event

apollo: {
// Passing in the event as prop conflicts with this.
// How can I fetch more attributes for a passed in object?
// Is this even possible? Do there is to fetch everything again?
// Is it possible with vue-apollo to just fetch the attendees
// and return them as property “attendees” in the EventDetails
// component?
event: {
query: gql`
query Event($id: ID!) {
event(id: $id) {
…event
attendees {
id
aasmState
event {
id
attendeeSelectionClosed
}
ticket {
id
companyName
position
}
}
}
}
${eventFragment}
`,
variables() {
return { id: this.eventId }
},
error(error) {
console.log(error)
}
}
}
}

The problem with this approach is, with the query named event, that I cannot pass in the already fetched event as a prop, so that event data has to be fetched again. Also, event details cannot be rendered immediately after expanding the EventDetails panel (waiting for query execution).

So is there a way to pass in the event data (not just the id) and query just the attendees via GraphQL? The only possible solution I’ve found is adding another query attendees to the GraphQL server, which I’d like to avoid, because attendees are always grouped under an event and we always know the parent event object.

But is this considered good architecture in GraphQL land? Add a query type for each an every object type you’re dealing with, even if always know the parent and querying via the parent works?

It’s well possible that I’m trying to do something stupid here, I’m still pretty new to GraphQL architectures.

the help is greatly appreciated.

Solution :

So is there a way to pass in the event data (not just the id) and query just the attendees via GraphQL?

No, ‘ask’ in parent query for parts needed at once in list/details view (f.e. attendees names). Every extension of parent query - asking for superset makes a new request, not using already fetched data (from cache). Ask for more ealier to save requests.

The only possible solution I’ve found is adding another query attendees to the GraphQL server, which I’d like to avoid, because attendees are always grouped under an event and we always know the parent event object.

In react (I don’t use vue) you can pass data as props from parent component - no need to mix this data into query request.

You can ask for attendees ‘directly’ (not by event) using simple filter on attendees, f.e. attendees (eventID:’some id’) {…. - of course realized by attendees resolver

[Vue.js] VueJS set axios header persist Subscribe to RSS

I’ve had a problem which my vuex state’s only lasts for web page refresh. Once web page is refreshed, data in the vuex store is vanished.

For overcome that I’ve used nice pluggin called Vuex persistestate
Now my vuex is persist.

But still I’ve a issue with the axios authorization header. I’ve set auth header in axios login action like this

actions: {
login({ commit }, payload) {
return new Promise((resolve, reject) => {
try {
axios.defaults.headers.common.Authorization = payload.token;
commit(‘setUser’, payload);
resolve();
} catch (error) {
reject();
}
});
},
},

But this auth headers value got undefined if I hit the refresh button. How do I overcome this problem?

Solution :

It’s because in the last session you called login and it saves the token in the axios instance. On refresh, the headers setting is gone. Vuex persisted state only save the Vuex, and the token is not in the Vuex.

I use js-cookie here.

// login action

axios.defaults.headers.common.Authorization = payload.token;
Cookies.set(‘token, payload.token);
commit(‘setUser’, payload);
resolve();

// Put it somewhere in the entry of the application, e.g: `main.js`, `App.vue`.
axios.defaults.headers.common.Authorization = Cookies.get(token);