I am creating a message board using TipTap in a Vue.js project with a Firebase DB. I would prefer not to have to use moment.js or another library as it seems superfluous.
This is the code for my simple method parse which I feel like is correct. Pretty vanilla JS if you ask me.
JavaScript
x
23
23
1
methods: {
2
pushContent() {
3
4
var timestamp = function() {
5
let d = new Date(),
6
year = d.getYear(),
7
day = d.getDay(),
8
month = d.getMonth(),
9
10
today = month + "/" + day + "/" + year;
11
12
return today;
13
}
14
15
16
db.ref('thanktank').push({
17
authorID: this.currentUserId,
18
text: this.editor.getHTML(),
19
timestamp: timestamp
20
})
21
this.editor.clearContent();
22
},
23
},
I first get a Vue warning saying this –
JavaScript
1
8
1
[Vue warn]: Error in v-on handler: "Error: Reference.push failed: first argument contains a function in property 'thanktank.timestamp' with contents = function timestamp() {
2
var d = new Date(),
3
year = d.getYear(),
4
day = d.getDay(),
5
month = d.getMonth(),
6
today = month + "/" + day + "/" + year;
7
return today;
8
}"
And then the error saying this –
JavaScript
1
8
1
Reference.push failed: first argument contains a function in property 'thanktank.timestamp' with contents = function timestamp() {
2
var d = new Date(),
3
year = d.getYear(),
4
day = d.getDay(),
5
month = d.getMonth(),
6
today = month + "/" + day + "/" + year;
7
return today;
8
}
Advertisement
Answer
you are trying to save a function in the database instead of calling it. Do like this:
JavaScript
1
6
1
db.ref('thanktank').push({
2
authorID: this.currentUserId,
3
text: this.editor.getHTML(),
4
timestamp: timestamp()
5
})
6
instead of passing the timestamp function itself, call it 🙂