No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Using Quasar components within an App Plugin

    Help
    3
    5
    633
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      turigeza last edited by

      I have a bunch of general functions which I would like to use all over my app. I have followed the guide how to create an app plugin here
      https://quasar-framework.org/guide/app-plugins.html

      And the plugin works just fine. However I do not know how to access quasar components from the plugin.
      Let’s say I want to notify somebody from within the plugin

      export default ({ app, router, Vue }) => {
          Vue.prototype.$padre = {
              Error (messages) {
                  ???.$q.notify({
                      color: 'negative',
                      position: 'top',
                      message: 'messages[0]',
                      icon: 'report_problem'
                  });
              }
          };
      };
      

      Is there a way to achieve the above apart from the obvious passing of $q every time you call the Error function

      Error (messages, $q) {
      
      this.$padre.Error(r.data, this.$q);
      

      I am new to Quasar as you can tell : ). Any help suggestion would be great. Thank you for the great work you guys put in.

      Geza

      1 Reply Last reply Reply Quote 0
      • T
        turigeza last edited by

        Also have an other question which is related and I don’t know how to solve.
        This is my axios plugin file in
        src/plugins/axios.js

        import axios from 'axios';
        
        // default responses
        axios.defaults.baseURL = 'https://api.piffle.ninja/';
        
        // Add a response interceptor
        axios.interceptors.response.use(function (response) {
            // Do something with response data
            if (response.data.messages) {
                response.data.messages.forEach(function (m) {
                    $q.notify({
                        color: 'negative',
                        position: 'top',
                        message: m.message,
                        icon: 'report_problem'
                    });
                });
            }
        
            return response;
        }, function (error) {
            // Do something with response error
            return Promise.reject(error);
        });
        
        export default ({ Vue }) => {
            Vue.prototype.$axios = axios;
        };
        

        My API always return messages in the same format so I would like to process those messages and convert them into quasar notifications. How can I reach $q (quasar) in here ?

        1 Reply Last reply Reply Quote 0
        • metalsadman
          metalsadman last edited by

          @turigeza It’s in the docs, if you use quasar components on a js file, just do import { [quasar component] } from 'quasar'. in your case Notify like so:

          import { Notify } from 'quasar' 
          ...
          Notify.({...})
          ...
          
          D 1 Reply Last reply Reply Quote 1
          • T
            turigeza last edited by

            @metalsadman Thank you ! I believe you but I couldn’t find it you know what it’s like. I went through the docs a couple of times already … : )
            That one liner helps me a great deal and reassures me yes it is how it supposed to be done. So thanks again : )

            1 Reply Last reply Reply Quote 0
            • D
              danbars @metalsadman last edited by

              @metalsadman said in Using Quasar components within an App Plugin:

              .

              For anyone who land here like I did, to call Notify this way you have to use the method create like this:
              Notify.create('message')
              or
              Notify.create({message:'message', position:'top'...})

              This is equivalent to calling
              this.$q.notify()
              from within a component

              1 Reply Last reply Reply Quote 0
              • First post
                Last post