meteor-vue2-example
meteor-vue2-example copied to clipboard
Error with 'setDefault' in app.vue
I cloned the example and followed all the add, remove and npm instructions mentioned in the Readme.md. On first run it throws the following error:
Exited with code: 1
.....meteor\packages\meteor-tool\1.4.3_2\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280
throw(ex);
TypeError: Cannot read property 'setDefault' of undefined
at imports/ui/App.vue:27:1
Not sure what's causing it. Perhaps something changed in the recent Session package?
I changed the faulting line from to: Session.setDefault("counter", 0)
to: Session.set("counter", 0)
which made the app run fine.
UPDATE
I changed it back to the orginal Session.setDefault("counter", 0)
, but I moved it into the 'beforeCreate' lifecycle hook, and that seems to work fine.
I have same issue. What exactly I need to do when you said " I moved it into the 'beforeCreate' lifecycle hook, and that seems to work fine." ?
export default {
...
beforeCreate(){
Session.setDefault("counter", 0);
},
...
};
I get this error too. It looks like App.vue is being run on the server, and Session is a client only package. Any thoughts?
Facing the same issue as well. Here's what I have in my meteor packages:
# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
[email protected] # Packages every Meteor app needs to have
[email protected] # Packages for a great mobile UX
[email protected] # The database Meteor supports right now
[email protected] # Compile .html files into Meteor Blaze views
[email protected] # Reactive variable for tracker
[email protected] # Meteor's client-side reactive programming library
[email protected] # CSS minifier run for production mode
[email protected] # JS minifier run for production mode
[email protected] # ECMAScript 5 compatibility for older browsers
[email protected] # Enable ECMAScript2015+ syntax in app code
[email protected] # Server-side component of the `meteor shell` command
[email protected] # Publish all data to the clients (for prototyping)
[email protected] # Allow all DB writes from clients (for prototyping)
akryum:vue-component
[email protected]
And this is what's in my App.vue:
<template>
<div id="root">
<h1>Sample first page</h1>
<p>you should appear</p>
</div>
</template>
<script>
import { Session } from 'meteor/session';
export default {
beforeCreate() {
Session.setDefault('counter', 0);
},
data() {
return {
count: 0,
}
},
meteor: {
data: {
count() {
return Session.get('counter');
},
}
},
methods: {
increment() {
Session.set('counter', this.count + 1)
},
}
};
</script>
Hope this helps.
@AsafAgranat thanks for the fix. It works for me as well :)