Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taro里获取实例为null #485

Open
Pentium286 opened this issue Aug 17, 2022 · 1 comment
Open

taro里获取实例为null #485

Pentium286 opened this issue Aug 17, 2022 · 1 comment
Assignees
Labels

Comments

@Pentium286
Copy link

问题描述

useReady(() => {
  getChildComponent();
});

const getChildComponent = () => {
  const { page } = getCurrentInstance();
  const calendar = page.selectComponent("calendar");
  console.log(calendar);
};

在taro里获取打印出来为null

@Pentium286
Copy link
Author

<template>
  <div class="calendarWrapper">
    <calendar
      class="calendar"
      :config="state.config"
      :afterCalendarRender="afterCalendarRender"
    />
  </div>
  <footTab />
</template>
<script setup>
import { reactive, ref } from "vue";
import Taro, { useReady, getCurrentInstance } from "@tarojs/taro";
import footTab from "@/components/common/footTab";

function afterCalendarRender(e) {
  console.log("afterCalendarRender: ", e);
}

definePageConfig({
  navigationBarTitleText: "打卡详情",
  usingComponents: {
    calendar: "../../../components/wx_calendar/v2/index",
  },
});

const state = reactive({
  config: {
    multi: true, // 是否开启多选,
    onlyShowCurrentMonth: true, // 日历面板是否只显示本月日期
  },
});

useReady(() => {
  getChildComponent();
});

const getChildComponent = () => {
  const { page } = getCurrentInstance();
  // console.log(page);
  const calendar = page.selectComponent(".calendar");
  console.log(calendar);
};
</script>
<style lang="scss" module>
.calendarWrapper {
  display: flex;
  width: 100%;
  overflow: hidden;
}
</style>

可以成功了,关键代码

function afterCalendarRender(e) {
  console.log("afterCalendarRender: ", e);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants