微信小程序-使用Component方法代替Page方法构造页面

一.使用Component方法的前提条件

在小程序js文件里使用Component方法代替Page方法需要在json文件里面定义usingComponents属性

复制代码
{
  "usingComponents": {}
}

二.注意事项

1.在page页面里使用的钩子函数和事件监听方法都需要写在methods对象里面

复制代码
  methods:{
    update(){
      this.setData({
        name:'jerry'
      })
    } ,
    onLoad(options){
      console.log(options)  
      console.log(this.data.id)
      console.log(this.properties.title)  
    }
  }
})

2.接收页面参数

2.1 通过onLoad(options)里面的options里面有接收的参数值

传参页面代码

复制代码
<navigator open-type="navigate" 
url="/pages/detail/detail?id=10&title=test">detail</navigator>

接收参数页面代码

复制代码
    onLoad(options){
      console.log(options)  
    }

2.2 通过properties接收参数,使用this.data或者this.properties获取接收的参数,前提得在properties对象里定义好参数,参数名和传参的参数名一致

复制代码
  properties:{
    id:{
      type:String,
      value:''
    },
    title:{
      type:String,
      value:''
    }
  }

    onLoad(options){
      console.log(this.data.id)
      console.log(this.properties.title)  
    }
相关推荐
肖有米XTKF86461 小时前
肖有米团队开发:青蓝山泉送水模式系统
小程序·团队开发·零售·csdn开发云
double_eggm4 小时前
微信小程序7
微信小程序·小程序
程序鉴定师5 小时前
上海小程序开发的坚实保障与行业优势解析
大数据·小程序
double_eggm16 小时前
微信小程序8
微信小程序·小程序
MageGojo16 小时前
小程序每日一谜怎么做:riddle 接口接入示例
windows·小程序·apache·谜语
kyh10033811201 天前
Cocos Creator 《打螺丝消除游戏》源码+实现
游戏·微信小程序·小程序·打螺丝小游戏源码·微笑小游戏源码
烂不烂问厨房1 天前
支付宝小程序camera录制视频并上传注意事项
小程序·音视频
PeanutSplsh1 天前
wx.setStorage 存的数据,没你以为的那么安全
微信小程序
我是伪码农2 天前
小程序125-150
小程序
帅次2 天前
讯飞与腾讯云:Android 实时语音识别服务对比选择
android·ios·微信小程序·小程序·android studio·android runtime