收藏
回答

如何解决page接收参数后page内的组件接收不到参数的问题?

Page的代码

Page({ 
  data: {
      currentId: ''
  },
  onLoad(options) {
      this.setData({currentId: options.id}) //从其他页面接收参数,此时的options.id有值
  },
})


<my-component id="{{currentId}}"></my-component>

my-component的代码

Component({
    properties: {
        id: {
            type: String
        }
    },
    observers: {
        id: function(val) {
            console.log(val)
        }
    },
})

现在的问题就是component里接收不到id的值

回答关注问题邀请回答
收藏

4 个回答

  • 你是人间四月天
    你是人间四月天
    2022-07-26


    参考这个看看: https://www.jianshu.com/p/8bfb8c20dd3a

    2022-07-26
    有用 2
    回复
  • 卖女孩的小火柴
    卖女孩的小火柴
    2022-07-26
    <my-component cid="{{currentId}}"></my-component>
    Component({
        properties: {
            cid: {
                type: String
            }
        },
        observers: {
            cid: function(val) {
                console.log(val)
            }
        },
    })
    


    id是關鍵字

    2022-07-26
    有用 1
    回复
  • 武曲心
    武曲心
    2022-07-26

    id是wxml关键词,不能做prop,换个名称比如vid

    2022-07-26
    有用
    回复
  • 茜茜又困了🐽
    茜茜又困了🐽
    2022-07-26
    <my-component curId="{{currentId}}"></my-component>
    properties: {
      curId: {
        type: String,
        value: ''
      }
    }
    observers: {
      'curId': function(curId) {
        console.log(curId)
      }
    }
    


    2022-07-26
    有用
    回复
登录 后发表内容