首页  >  问答  >  正文

如何在使用脚本设置时获取 Vue 组件数据

我需要重写 这段代码

export default Vue.extend<Props>({
  functional: true,
  render(h, { props, slots, data }) {
    const { href, external, target, type, button } = props;
    const slot = slots().default;
    console.log(data);
    ....

到 Vue 3 组合脚本设置, 所以我设法得到了

<script setup lang="ts">
 import {h, useSlots} from 'vue';
 const props = defineProps<Props>();
 const slots = useSlots();
 ...

但是我如何获取数据? 从这部分开始 -> render(h, { props, slot, data }) {

数据应该包含 domProps 如果有这样的..等

console.log(数据);

{
    {                                                                                                                                                                                                                                   
  attrs: {
    target: '_self',
    href: 'https://example.com',
    button: true
  },
  class: [
    'X-button',
    {
      'X-button--': false,
      'X-button--size-auto': true
    }
  ]
}

提前致谢

P粉392861047P粉392861047276 天前298

全部回复(1)我来回复

  • P粉707235568

    P粉7072355682024-01-17 10:30:01

    如果您仍然需要这个,

    useSlots().default() 返回槽的数据,包括 DOM 属性。

    回复
    0
  • 取消回复