跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 请教下前端我想在 vue 组件中使用企业微信 JSSDK 如何引用
未分類
7 1 月 2021

请教下前端我想在 vue 组件中使用企业微信 JSSDK 如何引用

请教下前端我想在 vue 组件中使用企业微信 JSSDK 如何引用

資深大佬 : phpxiaowangzi 4

如题,我用 vue-cli 脚手架创建的应用,然后 vue 组件里想使用企业微信 JSSDK,直接用 import 引用文件会报错,求教如何使用

<template>  <div>   <div>ibeacon</div>  </div> </template>  <script>  import Vconsole from 'vconsole'     import '../../assets/js/jweixin-1.2.0'       export default {   name:'Ibeacon',   mounted() {    var code = this.$route.query.code    if ( !code ) {     alert('无法获取 sess 标识')    } else {                 new Vconsole()                  var _this = this                 var reqData = {}                 reqData.type    = 'type1'                 reqData.version = '1.0'                 reqData.key     = '123456'                 reqData.parameter = {}                 reqData.parameter.code = code                  this.$http.post(                     'http://api.test.com/',                     reqData,                     {emulateJSON:true}                 ).then(function(response){                     if (response.data.errcode != 0) {                         alert(response.data.errmsg)                     } else {                         _this.sess = response.data.data                         this.getIbeacon()                     }                 }).catch(function(error){                     console.log(error)                 })                          }   },   methods:{    getIbeacon:function(){      var _this = this     var url = location.href.split('#')[0]      var reqData = {}     reqData.type    = 'type2'     reqData.version = '1.0'     reqData.key     = '123456'     reqData.parameter = {}     reqData.parameter.url = url      this.$http.post(      'http://api.test.com/',      reqData,      {emulateJSON:true}     ).then(function(response){       console.log(response.data.data)      wx.config({       beta: true,// 必须这么写,否则 wx.invoke 调用形式的 jsapi 会有问题       debug: false, // 开启调试模式,调用的所有 api 的返回值会在客户端 alert 出来,若要查看传入的参数,可以在 pc 端打开,参数信息会通过 log 打出,仅在 pc 端时才会打印。       appId: response.data.data.appId, // 必填,企业微信的 corpID       timestamp: response.data.data.timestamp, // 必填,生成签名的时间戳       nonceStr: response.data.data.noncestr, // 必填,生成签名的随机串       signature: response.data.data.signature,// 必填,签名,见 附录-JS-SDK 使用权限签名算法       jsApiList: ['startBeaconDiscovery', 'stopBeaconDiscovery', 'getBeacons','onBeaconUpdate','onBeaconServiceChange'] // 必填,需要使用的 JS 接口列表,凡是要调用的接口都需要传进来      })      var uuids = []      wx.ready(function(){       wx.startBeaconDiscovery({        uuids:uuids,        success(res) {         }       })      })      }).catch(function(error){       console.log(error)     })    }   }  } </script> 

大佬有話說 (5)

  • 資深大佬 : killmojo

    wx 没有 UMD 封装吧,简单点就直接放 index.html

  • 資深大佬 : que01

    https://www.npmjs.com/package/weixin-js-sdk

  • 資深大佬 : towry

    代码能写好就写好吧,为了你我他

  • 資深大佬 : KuroNekoFan

    @que01 这种非官方发布的 npm 包真的敢用吗

  • 資深大佬 : sjhhjx0122

    最简单的方法就是加到 public/index.html

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具