Skip to content
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

Can't throw a notification on "created" or "mounted" events #199

Open
lc-thomas opened this issue Jun 12, 2020 · 0 comments
Open

Can't throw a notification on "created" or "mounted" events #199

lc-thomas opened this issue Jun 12, 2020 · 0 comments

Comments

@lc-thomas
Copy link

<template>
  <div id="home">
    Vue webapp home :)
  </div>
</template>

<script>
import {HTTP} from '@/http-common.js'

export default {
  name: 'home',
  data () {
    return {
    }
  },
  notifications: {
    showWelcome: {
      title: 'Welcome :)',
      type: 'success'
    },
    showAPIError: { // You can have any name you want instead of 'showLoginError'
      title: 'API request failed',
      message: '',
      type: 'error' // You also can use 'VueNotifications.types.error' instead of 'error'
    },
  },
  methods: {
  },
  created(){
    this.showWelcome()
    HTTP.get('/api/home')
      .then(response => {
        this.showWelcome(response)
      })
      .catch(error => {
        this.showAPIError({message:error})
      })
  }
}
</script>

<style scoped>
</style>

So when I first load the page, I get errors : [Vue warn]: Error in created hook: "TypeError: this.showWelcome is not a function"

But if I edit one line, save the file, (using webpack dev server), then the page isn't reloaded but the componant is re-created, and then I get the notification.

So it looks like "notifications" functions are created after the component is created, so you can't really throw a notification until then.
Or am I doing something wrong ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant