【问题标题】:Vue component within code block, Vue attempting to render the template代码块中的 Vue 组件,Vue 试图渲染模板
【发布时间】:2021-07-19 09:14:05
【问题描述】:

我正在尝试在我的文档中显示示例 Vue 组件,但是 Vue 也在我的 Vue 组件中识别 template

vehicle-documents不是注册组件,同样放入如下代码:

Vue.config.ignoredElements = ['slide', 'slider', 'vehicle-documents'];

所以 Vue 忽略了组件本身:

If you want the modal make sure you add the click event and call the `open` function, and pass the `document` into this function call, as seen below.

```html
<vehicle-documents class="app" vehicle-id="">
    <template v-slot:default="slotProps">
        <button @click="slotProps.open(slotProps.document)">
            {{ slotProps.document.name }}
        </button>
    </template>
</vehicle-documents>
```

如何让 Vue 忽略 template 块?我在这个页面需要Vue,所以这不是一个简单的移除Vue的案例。

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    试试这个,添加v-pretype="text/x-template"

    <vehicle-documents class="app" vehicle-id="">
       <template v-pre type="text/x-template">
          <button @click="slotProps.open(slotProps.document)">
            {{ slotProps.document.name }}
          </button>
       </template>
    </vehicle-documents>
    

    【讨论】:

    • 似乎不起作用,但这可能是由于vehicle-documents 不是注册组件?
    • 您可以尝试将它们包装在另一个模板元素中吗?例如:&lt;template v-pre type="text/x-template"&gt; &lt;template v-slot:default="slotProps"&gt; &lt;/template&gt; &lt;/template&gt;
    • 似乎也不起作用,由于它解析模板,我仍然收到ReferenceError: slotProps is not defined 错误。
    • 可能v-pre只能用在实际组件上,我试试看
    • 如果您想将 html 显示为代码块以用于文档目的。然后,我建议您为此使用现成的软件包以避免额外的头痛。 EX:github.com/elisiondesign/vue-code-highlight这个包很容易实现,它有不同的主题可供选择。
    猜你喜欢
    • 2018-03-08
    • 1970-01-01
    • 2020-03-28
    • 2020-04-01
    • 1970-01-01
    • 2019-08-10
    • 2020-10-12
    • 1970-01-01
    • 2018-05-30
    相关资源
    最近更新 更多