Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // component.vue
- export default {
- ...
- methods: {
- myMethod: function() {
- this.$axios.get('/call', {
- }).then((resp) => {
- this.$resp.processResponse(resp); // here I'm using my plugin ($resp)
- }, (error) => {
- console.log(error);
- });
- }
- }
- }
- // plugins.js, loaded by Quasar boot, seems OK
- import Vue from 'vue';
- import resp from './plugins/responses.js';
- const plugin = {
- // eslint-disable-next-line no-shadow
- install (Vue) {
- Vue.prototype.$resp = resp; // this installs plugin, seems OK
- }
- };
- Vue.use(plugin);
- // responses.js
- // this is my plugin
- import Vue from 'vue';
- export default {
- processResponse() {
- const text = this.$t('label'); // throws error (see below)
- const text2 = Vue.prototype.$t('label'); // throws error (see below)
- }
- };
- // inside Vue!
- Vue.prototype.$t = function (key) {
- var values = [], len = arguments.length - 1;
- while ( len-- > 0 ) values[ len ] = arguments[ len + 1 ];
- var i18n = this.$i18n;
- // here fails with: "vue-i18n.esm.js?a925:182 Uncaught (in promise) TypeError: Cannot read property '_t' of undefined"
- return i18n._t.apply(i18n, [ key, i18n.locale, i18n._getMessages(), this ].concat( values ))
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement