我的插件;当前仅包含一个组件(在TypeScript中实现):
import _Vue, { PluginObject } from "Vue";
import MyComponent from "./MyComponent.vue";
const VuePlugin: PluginObject<void> = {
install(Vue: typeof _Vue): void {
Vue.component(MyComponent.name, MyComponent);
console.log("---");
}
};
export default VuePlugin;
由于MyComponent
,我希望Vue.component(MyComponent.name, MyComponent);
将在全球范围内可见。
用法:
import Vue from "vue";
import MyPlugin from "my-plugin/VuePlugin";
import RootComponent from "@SourceFiles:StaticView/RootComponent.vue";
(function executeApplication(): void {
Vue.use(MyPlugin);
new Vue({
el: "#Application",
template: "<RootComponent />",
components: { RootComponent }
});
})();
<template lang="pug">
MyComponent
div OK
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
@Component
export default class RootComponent extends Vue {}
</script>
直到console.log("---");
(来自插件代码)执行的代码都没有错误。
但是,发生了Vue错误:
Unknown custom element: <DevelopmentBuildAnywherePageVue> - did you register
the component correctly? For recursive components, make sure to provide the "name" option.
我错过了什么?
答案 0 :(得分:0)
这是错误的组件名称错误。 DevelopmentBuildAnywherePageVue
是VuePlugin
,是第二个清单中的文件名,而组件名是MyComponent
。错误是模板中存在真实项目文件名DevelopmentBuildAnywherePageVue
,而不是组件名MyComponent
。
感谢@nada的关注。