-
-
Notifications
You must be signed in to change notification settings - Fork 343
Can't access $route params in .vue component #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Take a look at whether #25 fixes your problem. I believe it should. It allows you to do firebase() {
// this now references the component, just like calling data() would.
}
// Or following your original attempt:
import db from '../services/firebase-service.js';
export default {
data() {
return {
}
},
firebase() {
return {
job: {
source: db.ref('jobs/' + this.$route.params.id),
asObject: true
}
}
}
} |
Doing this out of a function refers to the window object. |
Hey all! Sorry I might be missing something but when trying this I am just left with an empty object: <template>
<div>
{{ $route.params.id }}
{{ JSON.stringify(eventData) }}
</div>
</template>
<script>
import { db } from "../db";
export default {
data() {
return {
eventData: {},
};
},
firebase() {
return {
eventData: {
source: db.collection("events").doc(this.$route.params.id),
},
};
},
};
</script> Is there a different way that we are supposed to be getting the data when its coming from |
Ok I think what fixed it was to use the following instead of firestore() {
return {
eventData: db.collection("events").doc(this.$route.params.id),
};
}, |
Currently I'm having difficulty accessing any $route params from vue-router in order to utilize the params for vuefire queries. It seems like the vuefire property is tied to to a different context rather than the VueComponent context that other component hooks utilize.
Here is some code to explain:
My view component that needs access to the $route.params. This is what I'd hoped to use:
While currently I am doing this as a workaround, utilizing the global location object:
Since the "firebase" property is applied on the component level I assumed it would also be referencing the VueComponent context but instead it references a different context like this:
Is there a way to reference the current component context from within the firebase property? I have looked at #10 but I'm not sure it's applicable as I am using npm and webpack. Any help would be appreciated as I'm not too keen on the location hackery.
The text was updated successfully, but these errors were encountered: