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

[Drawer] 在 SFC 内导入 Drawer 组件无法使用 #1022

Closed
linesoft2 opened this issue Aug 11, 2023 · 6 comments · Fixed by #1030
Closed

[Drawer] 在 SFC 内导入 Drawer 组件无法使用 #1022

linesoft2 opened this issue Aug 11, 2023 · 6 comments · Fixed by #1030
Labels
bug Something isn't working

Comments

@linesoft2
Copy link
Contributor

tdesign-mobile-vue 版本

1.0.0-rc.6

重现链接

https://1024code.com/codecubes/rc0gauy

重现步骤

在 SFC 中引入Drawer,并在template中使用

期望结果

Drawer正常显示

实际结果

Drawer没有成功被 Vue 识别为组件

框架版本

Vue(3.3.4)

浏览器版本

Chromium(116.0.5845.62)

系统版本

Windows 11

Node版本

20.5.0

补充说明

No response

@github-actions
Copy link
Contributor

👋 @linesoft2,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@topjohncian
Copy link

将 import statement 改为如下后可用

import { default as TDrawer } from 'tdesign-mobile-vue/es/drawer/drawer';

@topjohncian
Copy link

此处有一疑问:独立出:

const Drawer = (options: DrawerOptions) => {
这一个 Drawer 为何用意

@topjohncian
Copy link

topjohncian commented Aug 11, 2023

在 JS 中建立和控制 Drawer 实例?

<template>
  <div>
    <!-- <t-drawer v-model:visible="visible" :items="baseSidebar" ></t-drawer> -->
    <t-button block variant="outline" size="large" theme="primary" @click="visible = true">基础抽屉</t-button>
  </div>
</template>
<script setup>
import { ref, watch, watchEffect } from 'vue';
// import { default as TDrawer } from 'tdesign-mobile-vue/es/drawer/drawer';
import { Button as TButton, Drawer } from 'tdesign-mobile-vue';

let visible = ref(false)
const baseSidebar = ref([
  {
    title: '菜单一',
  },
  {
    title: '菜单二',
  },
  {
    title: '菜单三',
  },
  {
    title: '菜单四',
  },
  {
    title: '菜单五',
  },
  {
    title: '菜单六',
  },
]);

const drawer = Drawer({ items: baseSidebar.value, onClose: () => { visible.value = false } })
watchEffect(() => {
  if (visible.value) {
    drawer.show()
  } else {
    drawer.hide()
  }
})
</script>

@topjohncian
Copy link

我认为官方可以在使用 Vue 渲染 DrawerPlugin 时抛出错误,如:

const handler = {

    destroy() {
      destroyOnClose.value = true;
      nextTick(() => {
        visible.value = false;
        document.body.removeChild(root);
      });
    },
    hide() {
      visible.value = false;
    },
    show() {
      visible.value = true;
    },
    update(options: DrawerOptions) {
      props.value = options;
    },
    render() {
      throw new Error("render is not allowed")
    }
  };

@linesoft2
Copy link
Contributor Author

我认为官方可以在使用 Vue 渲染 DrawerPlugin 时抛出错误,如:

const handler = {

    destroy() {
      destroyOnClose.value = true;
      nextTick(() => {
        visible.value = false;
        document.body.removeChild(root);
      });
    },
    hide() {
      visible.value = false;
    },
    show() {
      visible.value = true;
    },
    update(options: DrawerOptions) {
      props.value = options;
    },
    render() {
      throw new Error("render is not allowed")
    }
  };

如果官方不希望在组件内直接引用Drawer组件,那么在使用unplugin-vue-components的情况下会出现问题,因为使用该插件的情况下,就是在组件内直接引用的Drawer组件,希望官方能够处理好这个问题。

@anlyyao anlyyao added the bug Something isn't working label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants