微信小程序-使用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)  
    }
相关推荐
AI行业应用研究1 天前
破解活动统筹难题:会务小程序为活动组织提供全流程解决方案
小程序
万岳科技系统开发1 天前
直播电商APP搭建如何支持多门店与多主播模式
小程序·架构
戈伊1 天前
独立开发纪实:我如何用 Gemini CLI 和 Claude Code 打造一个“100% 含 AI 量”的小程序
微信小程序·ai编程
游戏开发爱好者81 天前
iOS应用性能监控:Pre-Main与Main函数耗时分析及Time Profiler使用教程
android·ios·小程序·https·uni-app·iphone·webview
StarChainTech2 天前
先享后付,正在悄悄改变电商的“信任游戏”
大数据·人工智能·游戏·微信小程序·小程序·软件需求
小羊Yveesss2 天前
门店小程序外卖配送搭建实战:配送对接、运费策略与多门店调度方案
小程序·apache
tianxiaxue12 天前
企业微信与小程序互联互通
小程序·企业微信
微擎应用2 天前
全渠道批发订货商城小程序管理系统
大数据·小程序
杰建云1672 天前
多商家入驻小程序平台怎么做
人工智能·小程序
Giggle12182 天前
开发上门维修(家政)小程序系统的核心功能和便捷方案
大数据·小程序