【发布时间】:2020-02-26 10:05:27
【问题描述】:
我的插件;目前只包含一个组件(在 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;
由于Vue.component(MyComponent.name, MyComponent);,我希望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.
我错过了什么?
【问题讨论】:
-
你在哪里声明了这个 DevelopmentBuildAnywherePageVue?
-
什么是
MyComponent.name? -
@nada 哦,这是第二个列表中的
VuePlugin.ts。解决这个问题就足够了。感谢您的评论!
标签: typescript vue.js vuejs2 vue-component