javascript - Yet another "Failed to mount component: template or render function not defined" from Vue
问题描述
Despite a lot of similar questions on SO, could not find an answer that would work for me. In essence, here is my very simplified Vue single-file component:
Listing.vue:
<template>
<section class="main">
Component
</section>
</template>
<script>
export default {
name: 'todoapp-listing',
…
}
</script>
Now I need to render it in a Web Component:
wrapper.js:
import Vue from 'vue';
import Listing from './src/Listing.vue';
class Wrapper extends HTMLElement {
connectedCallback() {
const appWrapper = document.createElement("div");
appWrapper.classList.add('todoapp');
this.attachShadow({ mode: "open" }).appendChild(appWrapper);
new Vue({
render: h => h(Listing),
}).$mount(appWrapper);
}
}
customElements.define("custom-wrapper", Wrapper);
When this Web Component is being added to a page, I get the following in the console:
[Vue warn]: Failed to mount component: template or render function not defined.
found in
---> <Listing> at src/Listing.vue
<Root>
Have tried adding vue$
alias to webpack config. Didn't help. Babels is running with @babel/preset-env
.
What am I missing here?
解决方案
推荐阅读
- libreoffice-calc - 如何在 LibreOffice Calc 中自动忽略空单元格(并在以后的函数中调整它们的角色)?
- javascript - 为 nest-js API 创建前端
- java - 我可以在后台使用 Firebase ML Kit 实时人脸检测作为服务吗?
- ios - 用户位置的简单 MKCircle 实现
- android - 如何使按钮的高度根据屏幕自动变化?
- javascript - JS Fetch API 很奇怪
- java - 是否可以在 Java 代码中使用扩展事件(Sql server Extended events)?
- python - Python 2.7-OpenCV-cv2resize 函数的矩阵到元组转换,导致 TypeError
- python - 如何使用 scipy 对图像进行卷积
- javascript - 使用 Cloud Functions 向所有用户发送 Firebase Cloud Message