一、Component方法
Component方法用于创建自定义组件,小程序页面也可以使用Component方法进行创建,从而实现复杂的页面逻辑开发。
使用Component方法构造页面,可以实现更加复杂的页面逻辑开发。
二、注意事项
1、要求.json文件中必须包含usingComponents字段。
2、里面的配置项要和Component中的配置项保持一致。
3、页面中Page方法有一些钩子函数、时间监听方法,这些钩子函数、时间监听方法必须放到methods对象中。
4、组件的属性properties也可以接收页面的参数,在onLoad钩子函数中可以通过this.data进行获取。
Component({// 组件的属性properties也可以接收页面的参数,在onLoad钩子函数中可以通过this.data进行获取properties:{id:String,title:String},data:{name:"tom"},methods:{updateDate(){this.setData({name:'jerry'})},onLoad(options){// 传参通过options接收console.log('页面加载')console.log(options)// 使用properties进行接受,使用this.data进行获取console.log(this.data.id)console.log(this.data.title)// 使用properties进行接受,使用this.properties进行获取console.log(this.properties)}}})