如何使用 @vue/coptions-api在TS文件中创建新组件?
我有一些需要在TS文件中创建的组件。通常,我通过调用新组件来创建,因为在我们的项目上,我们有vue-component-decorator
,但是现在我开始使用@vue/composition-api
,我可以' t将任何组件称为新的。
工作:
// SomeComponent.vue
import { Vue, Component } from 'vue-component-decorator';
@Component
export default SomeComponent extends Vue {}
// Any .ts file
const component = new SomeComponent();
不工作:
// SomeComponent.vue
import { defineComponent } from '@vue/composition-api';
export default defineComponent({});
// Any .ts file
const component = new SomeComponent();
I have some components that I need to create in the TS file. Usually, I create by calling new Component because on our project we have vue-component-decorator
but now I'm starting using @vue/composition-api
and I can't call any component as new.
Working:
// SomeComponent.vue
import { Vue, Component } from 'vue-component-decorator';
@Component
export default SomeComponent extends Vue {}
// Any .ts file
const component = new SomeComponent();
Not working:
// SomeComponent.vue
import { defineComponent } from '@vue/composition-api';
export default defineComponent({});
// Any .ts file
const component = new SomeComponent();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
createApp
来编程创建组件并安装IT:来源:
You need to use
createApp
to create the component and mount it programmatically:Sources: