前提・実現したいこと
ルーティングが解決される前にサーバからデータを取得してその間はローディング画面を出したいと思っています。
該当コード
ローディング画面を出せるようなプラグインは作成したのですが、beforeRouteEnterにてそれを使用する際はthisが使えないので
vue
1import Vue from 'vue'; 2... 3 4beforeRouteEnter(route, redirect, next) { 5 Vue.prototype.$plugin.open(); 6 ... 7 next(); 8}
上記のようにVueをimportして使用しています。
beforeRouteEnterでpluginを使用したい場合は上記のようにVueをインポートする以外の方法はないでしょうか?
その他
pluginのソースコードはおおよそ以下のようになっています。
js
1import Component from '@/component'; 2 3class Plugin { 4 constructor(Vue, options) { 5 this.Vue = Vue; 6 this.options = options; 7 this.Vm = {}; 8 } 9 10 open() { 11 let Loading = this.Vue.extend(Component); 12 let node = document.createElement('div'); 13 document.querySelector('body').appendChild(node); 14 this.Vm = new Loading(); 15 this.Vm.$mount(node); 16 } 17 18 close() { 19 this.Vm.$destroy(); 20 let elem = this.Vm.$el; 21 elem.remove(); 22 } 23} 24 25Plugin.install = function (Vue, options) { 26 Vue.prototype.$plugin = new Plugin(Vue, options); 27}; 28 29export default Plugin;
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/16 08:43
2019/11/18 10:21