微信小程序url参数传递
来源:互联网 发布:家庭影院网络播放器 编辑:程序博客网 时间:2024/06/06 11:43
叨叨两句
在之前的博客中glacier简单的介绍了一下微信小程序,并且写了个Demo带大家入了个门;
点击回顾
这次我们学习下微信小程序很重要的一点,URL传参。
干货
app.js
App({ onLaunch: function () { console.log('App Launch') }, onShow: function () { console.log('App Show') }, onHide: function () { console.log('App Hide') }})
app.json
{ "pages":[ "pages/index/index", "pages/flowers/flower" ], "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#BBDEF8", "navigationBarTitleText": "Glacier", "navigationBarTextStyle":"black", "backgroundColor": "#f7f7f7" },}
以上是最基础的配置小伙伴们不要忘了在pages里面加上我们需要用到的页面
index.js
var flag = 0;Page({ data:{ // text:"这是一个页面" //这是一个变量的数组,这个里面申请的变量都可以在 wxml中使用 }, click:function(event){ console.log("点击了文字");//这行是为了测试,点击事件有没有过来 flag = event.currentTarget.id;//获取到id console.log(flag); wx.navigateTo({url:'../flowers/flower?id='+flag}); }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 console.log("Page onLoad"); }})
index.wxml
<view><image class="image_frame" src="url地址" mode="aspectFill" catchtap="click" id="1" > </image><image class="image_frame" src="url地址" mode="aspectFill" catchtap="click" id="2" > </image><text class="footer">更多内容持续更新中...</text></view>
index.wxss
.userinfo { display: flex; flex-direction: column; align-items: center;}.userinfo-avatar { width: 128rpx; height: 128rpx; margin: 20rpx; border-radius: 50%;}.userinfo-nickname { color: #aaa;}.usermotto { margin-top: 200px;}.window{ color:#4995fa;}.window-red{ color:#D23933;}.image_frame{ width: 200rpx; height: 200rpx; margin: 20rpx 10rpx 0 30rpx; display: inline-flex;}.footer{ display: flex; flex-direction: row; justify-content: center; align-items: center; font-size: 25rpx; color: #ccc; margin:20rpx 0 0 0;}
flower.wxml
<view class="classname"><image src="{{imgUrl}}" mode="widthFix" style="width:750rpx"></image></view>
这里{{imgUrl}}
这种用法上次已经说过了,这种用法类似于变量,不过要在js文件中定义,然后再wxml文件中才能引用。再js文件中修改了之后别忘了使用this.setData
刷新一下这个变量。
flower.js
//设置一个默认的imgUrlvar imgUrl = 'url地址';Page({ data:{ imgUrl }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 switch(options.id){ case "2": imgUrl = 'url地址';break; case "3": imgUrl = 'url地址';break; } //别忘了刷新一下imgUrl参数使之生效 this.setData({ imgUrl }) }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ // 页面显示 }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 }})
效果
最后
因为是公司项目有一些代码不方便贴出来,贴出来的代码做学习之用。希望大家能通过我的博客学到些微信小程序的开发技巧。:)
这是我的博客 http://www.glacier.market
2 0
- 微信小程序url参数传递
- 微信小程序-navigator 跳转url传递参数
- 微信小程序-navigator 跳转url传递参数
- 微信小程序-参数传递
- 小程序中跳转的实现和url传递参数
- 传递中文url参数
- URL传递中文参数
- url传递参数乱码
- URL传递中文参数
- Intent传递URL参数
- url传递参数乱码
- URL传递参数
- URL参数传递
- url传递参数乱码
- 微信小程序传递参数方法?
- URL中文参数传递问题
- URL中文参数传递问题
- html url传递参数问题
- 基于DCT变换的信息隐藏(数字水印)嵌入算法的设计(Matlab)
- 《连载 | 物联网框架ServerSuperIO教程》- 17.集成Golden实时数据库,高并发保存测点数据。附:3.4 发布与版本更新说明。
- matlab 连通区域 显示 边缘检测显示到原图
- Cookie,Session
- 布林带(BOLL)技术指标
- 微信小程序url参数传递
- SQL语句汇总(三)——聚合函数、分组、子查询及组合查询
- Python教程精华版(二)
- Backbone 模型
- JDBC复习
- houghline
- 《连载 | 物联网框架ServerSuperIO教程》- 18.集成OPC Client,及使用步骤。附:3.5 发布与更新说明。
- Centos7下查询java安装路径
- 基础——Linux命令学习