vue2.0 微信oauth认证的正确调用位置

运行在微信端的项目,很重要的环节是oauth认证;那在vue项目中,在何时何地调用oauth认证最合适呢?

经过观察,在项目启动过程中,会执行main.js文件;所以我将认证放在main.js中操作;

当oauth认证完成后,再启动模块;这样就不用去每个模板页面调用oauth认证;

oauth认证的js,我就不在这里写了;这里主要是告诉大家应该放在哪里;看下面的代码

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

// 微信oauth认证
oAuth.cfg(Config.uid, Config.isDebug, Config.scope);
oAuth.checkToken((apiopenid, apitoken) => {
  Config.apiopenid = apiopenid;
  Config.apitoken = apitoken;
  console.log(Config);
  // 认证完成后,启动模块
  new Vue({
    el: '#app',
    router,
    template: '<App/>',
    components: { App }
  })
});
原文地址:https://www.cnblogs.com/minigrasshopper/p/7873170.html