如何克服:'v-slot'指示词必须由自订元素拥有,但'slot'不是,eslint-plugin-vue?

dxxyhpgq  于 2022-12-14  发布在  Vue.js
关注(0)|答案(2)|浏览(1257)

我有Vue.js应用程序和组件代码的关键部分看起来如下:
specific-modal.vue:

<template>
  <v-modal-dialog
    :visible="isModalVisible"
    title="CONNECTION"
    okText="Save"
    cancelText="Cancel"
    :isSaveDisabled="isDisabled"
    :width="550"
    :height="620"
    @ok="onOk"
    @cancel="onCancel"
    @hiding="onHiding"
  >
    ...

base-modal.vue:

<template>
  <DxPopup
    v-bind="$attrs"
    :hide-on-outside-click="true"
    :drag-enabled="true"
    :wrapper-attr="popupAttributes"
    position="center"
    v-on="$listeners"
    @hiding="onHiding"
  >
    <slot />
    <slot name="footer">
      <DxToolbarItem template="save-template" toolbar="bottom" location="after" />
      <template #save-template>
        <DxButton text="Ok" @click="onOk" />
      </template>

      <DxToolbarItem template="cancel-template" toolbar="bottom" location="after" />
      <template #cancel-template>
        <DxButton text="Cancel" @click="onCancel" />
      </template>
    </slot>
  </DxPopup>
</template>

<script>
import { DxPopup, DxToolbarItem } from "devextreme-vue/popup";
import DxButton from 'devextreme-vue/button';
...

#save-template带有红线下划线,并显示一条消息:
'v-slot' directive must be owned by a custom element, but 'slot' is not.eslint-plugin-vue
如何克服这个问题?
EDIT:
如果我做如下:

<slot />
<slot name="footer">
  <DxToolbarItem template="save-template" toolbar="bottom" location="after" />
  <custom-element>
    <template #save-template>
      <DxButton text="TEST" @click="onOk" />
    </template>
  </custom-element>

  <DxToolbarItem template="cancel-template" toolbar="bottom" location="after" />
  <custom-element>
    <template #cancel-template>
      <DxButton text="Cancel" @click="onCancel" />
    </template>
  </custom-element>
</slot>

当我运行应用程序时,我收到以下错误:

[Vue warn]: Unknown custom element: <custom-element> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

我不知道该怎么做。

dgtucam1

dgtucam11#

<template #save-template<template v-slot='save-template'的简写。
因此,eslint规则抱怨<template v-slot='save-template'被拥有(具有父元素),而不是自定义元素(是)。
<slot>类似于外部组件可以用来添加数据的占位符。但在您的代码中,您似乎是在说占位符在代码内部提供了占位符。
要解决此问题,请将父插槽标记更改为其他标记。或者,将模板标记包含在如下标记中:

<template>
    <DxPopup
        v-bind="$attrs"
        :hide-on-outside-click="true"
        :drag-enabled="true"
        :wrapper-attr="popupAttributes"
        position="center"
        v-on="$listeners"
        @hiding="onHiding"
    >
        <slot />

        <slot name="footer">
            <DxToolbarItem template="save-template" toolbar="bottom" location="after" />

            <!-- Add custom element wrapping here -->
            <custom-element>
                <template #save-template>
                    <DxButton text="TEST" @click="onOk" />
                </template>
            </custom-element>
        </slot>
    </DxPopup>
</template>

更多详情:

lp0sw83n

lp0sw83n2#

我在Stackoverflow上找到了解决方案:

<template>
  <DxPopup
    v-bind="$attrs"
    :hide-on-outside-click="true"
    :drag-enabled="true"
    :wrapper-attr="popupAttributes"
    position="center"
    v-on="$listeners"
    @hiding="onHiding"
  >
    <slot />
    <slot name="footer">
      <DxToolbarItem template="save-template" toolbar="bottom" location="after" />
      <DxToolbarItem template="cancel-template" toolbar="bottom" location="after" />
    </slot>

    <template #save-template>
      <DxButton text="TEST" @click="onOk" />
    </template>
    <template #cancel-template>
      <DxButton text="Cancel" @click="onCancel" />
    </template>
  </DxPopup>
</template>

相关问题