Global config for quasar plugin like notify



  • Hi there,
    First of all, thank you for such a great framework.
    I have a question, when using plugin like Notify, is there a global config or something like that?
    For example, I want to have the notification on on the top right by default.
    So I don’t have to add position to the config object each time we call it.
    Like this:

    this.$q.notify({
       type: "warning",
       message: "Email or password is not correct.",
       position: "top-right"
    });
    

    Thank you very much!



  • @trongdong

    I have a custom plugin which basically wraps the Notify plugin with some custom config…

    import {
      Notify
    } from 'quasar'
    
    let defaults = {
      color: 'white',
      textColor: 'black',
      timeout: 2000,
      position: 'top'
    }
    
    let notifyInstance = (options) => {
      if (typeof options !== 'object') {
        options = Object.assign({}, defaults, { message: options })
      }
    
      let optionsToUse = Object.assign({}, defaults, options)
    
      return Notify.create(optionsToUse)
    }
    
    export default ({ Vue }) => {
      Vue.prototype.$notify = notifyInstance
    }
    
    export {
      // for use outside components
      notifyInstance as Notify
    }
    


  • @GastroGeek Thanks for your help.
    That’s an option but I don’t like that much.
    Do we have an option to load the options with the plugin or something like that should be cleaner?



  • @trongdong the Quasar plugins (like Notify, Dialog, etc) initialization is done in the Quasar source code. You should not modify that because updates will overwrite it. The best way is to wrap them as @GastroGeek showed.

    This is true for any plugin like this show for axios https://quasar-framework.org/guide/app-plugins.html#Accessing-data-from-plugins



  • @genyded thanks for your clarification.
    If so I think the best scenario is quasar.conf.js come up with some sort of modify plugin’s default value.



  • @GastroGeek is indeed using the right approach here, as things stand in the repo. If you really want to be able to configure it in quasar.conf.js then you should file a feature-request for it at github.


  • Admin

    This is one feature that will land in Quasar v0.16.1 (do not mistake this with CLI version).