Background account
Although I am now just npm install wilddog a bit, but I have a hunch that will not be so smooth. I just know it won't go so well, see I'm here to pits. Wilddog with the judge on the internet to say very clearly and there is video I will not say more, has not been used in depth, for the time being not to say.
Problem
A component of the. Vue file is its own separate section, and when I create a ref connection Wilddog database object in the first. vue file, what do I do when I need to use it in another. vue file?
Workaround
- First of all, I think in the second. Vue file in the creation of a ref connection database is OK, after all, it is connected to the database, there is no problem. Take for granted the failure Oh. Pass, of course, there may be a problem with my use, if the correct way to open, please be sure to tell me, do not waste my toss for two days.
There is certainly can solve the vuex, but I think kill chicken with slaughter sledgehammer, and if continue to use other people's plug-in, then I will not understand the principle.
So what? Create a global ref object, then how do you create it? Direct Baidu words vue-cli create global variables, there will be many answers, I personally test success is to click here
is actually creating a Vue plugin
Vue Plug-in principle
Vue Documentation
Ways to create plug-ins:
- Define an Action object that contains the classes you need, variables, etc.
var refHelper = { ref:myRef}
in refhelper you can add the methods you want to global variables and so on.
- Export by default from export
export default refHelper;
- Introduced in the Main.js
import ref from ‘./assets/js/Tool‘
- Attach the introduced object to the Vue prototype, and be aware that the Refhelper object
Vue.prototype.refHelper = ref
you set is the one that is mounted.
- Use:
this.refHelper.ref
It can be used anywhere in the file, I'm not mistaken.
- The essence of this writing should be the same, all hanging on to the Vue prototype, feeling a little more beautiful
Paste Code
//Main.jsImportref from './assets/js/tool '//Vue.prototype.refHelper = ref//Method oneVue.use (ref)//Tool.jsImport Wilddog from ' Wilddog ' //Initialize varConfig = {authdomain:"Lorry.wilddog.com", Syncurl:"Https://lorry.wilddogio.com"}; Wilddog.initializeapp (config);varMyref = Wilddog.sync ().ref();//The first method//var refhelper = {//Ref:myref// }//export default refhelper;Exportdefault{Install (vue,options) {Vue.prototype.ref= function () {returnMyref; } }}
Summary
I do not know what will happen to the pit dad, so just a summary. Found himself or only understand the use of tools, but did not seriously study the principle of the tool, so down also carefully read the ES6 book, Vue component part, only a little bit small harvest, the pressure of junior internship is great, learning
Wilddog & Arcgisapi & VUE-CLI plug-in, sinkhole Road (iii)