Open AsafAgranat opened 7 years ago
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.
meteor-base@1.1.0 # Packages every Meteor app needs to have
mobile-experience@1.0.4 # Packages for a great mobile UX
mongo@1.1.18 # The database Meteor supports right now
blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views
reactive-var@1.0.11 # Reactive variable for tracker
tracker@1.1.3 # Meteor's client-side reactive programming library
standard-minifier-css@1.3.4 # CSS minifier run for production mode
standard-minifier-js@2.1.0 # JS minifier run for production mode
es5-shim@4.6.15 # ECMAScript 5 compatibility for older browsers
ecmascript@0.8.0 # Enable ECMAScript2015+ syntax in app code
shell-server@0.2.3 # Server-side component of the `meteor shell` command
autopublish@1.0.7 # Publish all data to the clients (for prototyping)
insecure@1.0.7 # Allow all DB writes from clients (for prototyping)
akryum:vue-component
session@1.1.7
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 :)
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:
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.