组件父传子
先是创建
创建这两个文件来传
先把welcome引入到app.json 切记要把这个放在最上面才会最先显示这个页面
如下如代码
<view>
<my-components myvalue="父亲的值"></my-components>
</view>
<view>
我是模板我是组件->
{
{myvalue}}
<button type="primary" bindtap="clickFn">点我修改值</button>
</view>
mponent({
/**
* 组件的属性列表
*/
properties: {
myvalue:{
type:"string",
value:"默认值",
observer:(newValue,oldValue)=>{
console.log(newValue,oldValue)
}
}
},
/**
* 组件的方法列表
*/
methods: {
clickFn(){
// console.log("修改的父亲的值")
this.setData({
myvalue:"修改的值"
})
}
}