zoukankan      html  css  js  c++  java
  • 小程序页面传值的几种方式

    1.  url传值

    list.wxml:
    
     <view class="playIcon">
        <image src="../../iconfont/play_init.png"  bindtap="playAudio" data-songid="{{song.song_id}}"></image>
    </view>
    
    
    list.js:
    
    playAudio: function (event) {
        let songid = event.currentTarget.dataset.songid;
        var that = this;
        wx.navigateTo({
          url: '/pages/listDetail/listDetail?title=' + songid,
        })
    }    
    
    listDetail.js:
    
     onLoad: function (options) {
        var that = this;
        console.log('options',options.title) 
    
    }

    2.app.globalData  设置全局变量

    app.js: 设置全局变量
    
    App({
    globalData: {
    userInfo: null,
    host:'http://localhost:8000'
    }
    })
     
    
    index.js:
    
    const app = getApp()
    // app.globalData = '这里也可以设置值',
    console.log(app.globalData.host)

    3.

    wx.setStorageSync()/wx.getStorageSync()  将值写在本地缓存里,最大支持10M,可以存些文本之类的,音频视频就算啦.这里是同步写法,异步见开发文档
    list.js:
    
    存值到本地缓存
    
    wx.setStorageSync('title',data)
    
     
    
    listDetail.js:
    
    从本地缓存取值
    
    let info = wx.getStorageSync('title')
    
    console.log('info',info)
  • 相关阅读:
    Java io流 之file类(文件和文件夹)
    异常处理
    封装
    面向对象与类
    包与模块的使用
    模块
    递归函数
    迭代器
    装饰器
    函数基础2
  • 原文地址:https://www.cnblogs.com/aloehui/p/8907116.html
Copyright © 2011-2022 走看看