组件的定义引入传参

组件父传子
先是创建
在这里插入图片描述
在这里插入图片描述
创建这两个文件来传
先把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:"修改的值"
      })
    }
  }

猜你喜欢

转载自blog.csdn.net/weixin_54645137/article/details/113446359