jiangping
2025-07-16 712c080180b9e8511b4e1c26d707882a557b26c7
small-program/App.vue
@@ -1,7 +1,27 @@
<script>
   import { mapState } from 'vuex'
   export default {
      computed: {
         ...mapState(['userInfo','openid'])
      },
      onLaunch: function() {
         console.log('App Launch')
         var that = this;
         console.log(this.userInfo)
         if (!this.userInfo || JSON.stringify(this.userInfo) == '{}') {
            uni.login({
               provider: 'weixin',
               success: async function (loginRes) {
                  let { code } = loginRes;
                  let res = await that.$u.api.wxLogin({ code })
                  if (res.code === 200) {
                     that.$store.commit('setToken', res.data.token)
                     that.$store.commit('setOpenid', res.data.openid)
                     that.$store.commit('setUserInfo', res.data.member)
                     that.$isResolve()
                  }
               }
            });
         }
      },
      onShow: function() {
         console.log('App Show')
@@ -13,6 +33,5 @@
</script>
<style lang="scss">
   /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
   @import "uview-ui/index.scss";
   @import "uview-ui/index.scss";
</style>