zoukankan      html  css  js  c++  java
  • uniapp 开发微信小程序总结(三)mixin

    share mixin 重要用于 设置分享类容、重定向Url

     1 import {mapState,mapMutations} from 'vuex'
     2 export default {
     3     computed:{
     4         ...mapState('login',['userInfo','redirectUrl']),
     5     },
     6     onUnload() {
     7         if(this.redirectUrl){
     8             if(this.isLogin){
     9                 const token = uni.getStorageSync('token');
    10                 const getPhone = uni.getStorageSync('getPhone');
    11                 if(token&&!getPhone){
    12                     this.clearRedirectUrl()
    13                 }
    14             }
    15         } 
    16     },
    17     methods:{
    18         ...mapMutations('poster',['GETSHAREINFO']),
    19         ...mapMutations('login',['GETREDIRECTURL']),
    20         setShareInfo(shareTitle,title,shareImg,previewImg,statistics){
    21             let inviteUserId = undefined
    22             if(this.userInfo){
    23                 inviteUserId = this.userInfo.id
    24             }
    25             var pages = getCurrentPages();
    26             var page = pages[pages.length - 1];
    27             let path = '/' + page.route + '?code='+this.code+'&inviteUserId='+ inviteUserId
    28             this.GETSHAREINFO({shareInfo:{
    29                     title: shareTitle || title,
    30                     image: shareImg || "",
    31                     type: "share",
    32                     poster: previewImg,
    33                     path: path,
    34                     statistics,
    35                     code:this.code
    36                 }
    37             })
    38         },
    39         // 重定向页面Url
    40         getRedirectUrl(){
    41             let pages = getCurrentPages();
    42             let page = pages[pages.length - 1];
    43             // let {scene} = page.options
    44             let param = ''
    45             for(const key in page.options){
    46                 console.log(page.options[key])
    47                 param += key+'='+page.options[key]
    48             }
    49             let path = page.route + (param?'?'+param:'');
    50             this.GETREDIRECTURL({redirectUrl:{url:path,type:1}}) //小程序内部页面
    51         },
    52         // 清除重定向
    53         clearRedirectUrl(){
    54             this.GETREDIRECTURL({redirectUrl:null})
    55         }
    56     }
    57 }
  • 相关阅读:
    rails中输出excel
    Rails IDE 有很多选择,但是具体到ubuntu 64bit 选择的余地就不多了,这里选择Aptana Studio 3 Beta
    linux中查看系统资源占用情况的命令
    GIT GUI使用
    linux下的c 环境配置vim
    oracle11 忘记密码
    Aptana_Studio 介绍和应用
    linux root命令忘记以及挂载U盘
    程序员创业生死一线 最后归宿在哪里?
    如何使用Log4j? .
  • 原文地址:https://www.cnblogs.com/kitty-blog/p/14043431.html
Copyright © 2011-2022 走看看