problem description
create the component with vue-cli 3, publish it to npm, and quote the Times error:
Failed to mount component: template or render function not defined.
related codes
hellocomp.js
export default {
name: "HelloComp",
render(h) {
return (
<div class="h-comp">
Hello from Component
</div>
)
}
}
index.js
import HelloComp from "./hellocomp.js"
HelloComp.install = function(Vue, options = {}) {
Vue.component(HelloComp.name, HelloComp)
}
if (typeof window !== "undefined" && window.Vue) {
Vue.component(HelloComp.name, HelloComp)
}
export default HelloComp
webpack.config.js
module.exports = {
entry: "./src/index.js",
...
then npm publish,
reference Test.vue in the project
<template>
<div>
<hello-comp />
</div>
</template>
import HelloComp from "hello-comp"
@Component({
components: {
HelloComp
}
})
export default class Test extends Vue {
...
after starting, you see the following error in console
[Vue warn]: Failed to mount component: template or render function not defined.
exactly what went wrong?
if it is not published to npm, it is normal to put it directly in the project