TypeError: formatDate is not a function appears in Vue.js

Asked 2 years ago, Updated 2 years ago, 127 views

We create web apps using Vue.js, Buefy, and firebase.
You are running the @click event and publishing by clicking the button on the information you entered in the form.
At that time, the following error will appear.
It's probably a shabby mistake, but I hope you enjoy it.

Error

TypeError:formatDate is not a function
Vue warn—Error in v-on handler: "TypeError: formatDate is not a function"
found in
--- ><BButton>
<Create> at src/views/Create.vue
<App> at src/App.vue
<Root>

Tried

const date=this.$date(new Date(), "DDMMMMM,YYY") to
Try const date=this.$date(new Date(), "ddMMMMM,yyy").
constdate=firebase.firestore.Timestamp.fromDate(newDate(`2020/01/01 00:00:00`)); but the results did not change.

Current Source Code

<section>
    <h2class="title is-3">title</h2>
         <b-input type="text" class="new_input" placeholder="Title" v-model="title">/b-input>

         <b-input type="text" class="tag" placeholder="tag" v-model="tag"@keypress.enter="addTag">/b-input>
        <div v-if="tags.length>0" class="tags">
          <lib-for="(tag,idx)intags":key="idx" class="content is-rounded">
           {{ tag}}
           <span class="cursor-pointer" @click="removeTag"></span>
          </li>
        </div>
        <textarea class="textarea" placeholder="Content" v-model="content">/textarea>
      <b-button type="is-primary"@click="publish" expanded>Post </b-button>
  </section>
    
    <script>
    import firebase from 'firebase';
    import {auth} from '@/main'
    import {db} from '@/main'
    export default {
      data(){
        US>return{
          title:',
          tags: [ ],
          content:',
          tag:',
          currentUser: {}
        }
      },
      created(){
        auth.onAuthStateChanged(user=>{ 
          This.currentUser=user
        })
      },
      methods: {
        addTag(){
          this.tags.push (this.tag),
          This.tag='"
        },
        removeTag(idx){
          This.tags.splice(idx,1)
        },
        publish(){
          const date = this.$date(new Date(), "ddMMMM,yyy")
          db.collection('posts').add({
            title —This.title,
            tags —this.tags,
            content —This.content,
            createdAt:date,
            uid —this.currentUser.uid
          })
          .then(post)=>
            this.$router.push('/post/'+this.post.uid+'/'+this.post.id),
            alert('The post got published!')
          )
        }
      }
    }
    </script>

vue.js firebase

2022-09-30 16:58

1 Answers

What's the point of saying this.$date?
I don't think the Vue property has a date (although I have data)

Unless you define your own date separately, it doesn't exist in the first place, so you won't be able to access it.

Also, I think there is no built-in function to format Date like that by JS alone.

Did you get the code from somewhere?

JS is a little poor at date manipulation, so it is often implemented using momentjs.

at the terminal
npm install moment

Or

 yarn add moment

Then

import moment from 'moment'
 // (omitted)
const date = moment().format('ddMMMMM,yyyy')

I think it will pass by


2022-09-30 16:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.