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

发布于:2023-09-16 ⋅ 阅读:(64) ⋅ 点赞:(0)

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

父组件代码

引入

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 });
    },
  },
});

希望此文章能帮助到你

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到