• 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 }
      })
    });
  • 相关阅读:
    [原]80386中断表
    [原]elf可执行连接文件格式
    [原]nasm语法
    VLAN基础配置及Access接口
    配置hybird接口
    配置Trunk接口
    [导入]Oracle常用技巧和脚本
    [导入]ORACLE 常用的SQL语法和数据对象
    [导入]Oracle 基本知识
    [导入]Oracle特殊包
  • 原文地址:https://www.cnblogs.com/minigrasshopper/p/7873170.html
Copyright © 2020-2023  润新知