Advertisement
mbazs

Quasar + Vue plugin issue

Jun 11th, 2020
3,358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // component.vue
  2. export default {
  3.     ...
  4.     methods: {
  5.         myMethod: function() {
  6.             this.$axios.get('/call', {
  7.             }).then((resp) => {
  8.                 this.$resp.processResponse(resp); // here I'm using my plugin ($resp)
  9.             }, (error) => {
  10.                 console.log(error);
  11.             });
  12.         }
  13.     }
  14. }
  15.  
  16. // plugins.js, loaded by Quasar boot, seems OK
  17. import Vue from 'vue';
  18. import resp from './plugins/responses.js';
  19.  
  20. const plugin = {
  21.     // eslint-disable-next-line no-shadow
  22.     install (Vue) {
  23.         Vue.prototype.$resp = resp; // this installs plugin, seems OK
  24.     }
  25. };
  26. Vue.use(plugin);
  27.  
  28.  
  29. // responses.js
  30. // this is my plugin
  31. import Vue from 'vue';
  32.  
  33. export default {
  34.     processResponse() {
  35.         const text = this.$t('label'); // throws error (see below)
  36.         const text2 = Vue.prototype.$t('label'); // throws error (see below)
  37.     }
  38. };
  39.  
  40. // inside Vue!
  41. Vue.prototype.$t = function (key) {
  42.     var values = [], len = arguments.length - 1;
  43.     while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ];
  44.  
  45.     var i18n = this.$i18n;
  46.  
  47.     // here fails with: "vue-i18n.esm.js?a925:182 Uncaught (in promise) TypeError: Cannot read property '_t' of undefined"
  48.     return i18n._t.apply(i18n, [ key, i18n.locale, i18n._getMessages(), this ].concat( values ))
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement