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)