微信小程序父组件向子组件传参,子组件样式无效问题处理

微信小程序父组件向子组件传参,子组件样式无效问题处理

父组件代码

引入

json

  "usingComponents": {
    
    
    "evaluate":"../evaluate/evaluate"
  },

wxml

  <evaluate id='1111'></evaluate>

子组件代码

json

{
    
    
  "usingComponents": {
    
    
    "van-rate": "@vant/weapp/rate/index"
  },
  "component": true, //必须
  "options": {
    
     
    "addGlobalClass": true  //必须加这个 不然子组件css无效
  }
}

js

Component({
    
    
  data: {
    
    
	//基本数据
  },
  lifetimes: {
    
    
    attached() {
    
    
    //传递参数接受 this.xxx
      console.log(this.id);
    },
  },
  //自带方法
  pageLifetimes: {
    
    
    show() {
    
    
      console.log(2);
    },
  },
  //接受类似 vue props
  properties: {
    
    
    id: {
    
    
      type: Number,
      value: 0,
    },
  },
  //自己自定义方法
  methods: {
    
    
    tabsTo(e) {
    
    
      const statusId = e.currentTarget.dataset.id;
      this.setData({
    
     statusId });
    },
  },
});

希望此文章能帮助到你

猜你喜欢

转载自blog.csdn.net/weixin_44255044/article/details/132764212