代码之家  ›  专栏  ›  技术社区  ›  Samuel Neff

将nativescript vue模板放在单独的文件中时,“未知的自定义元素:<div>”

  •  0
  • Samuel Neff  · 技术社区  · 6 年前

    我正在尝试将vue模板和typescript分离成不同的文件(以使其更好地与ide一起工作)。

    当我运行应用程序时,即使我没有声明 <div> 元素在模板中的任何位置。

    当我把模板和代码放在同一个文件中时,它工作得很好。

    JS: '{NSVue (Vue: 2.5.17 | NSVue: 2.0.2)} -> CreateElement(NativeFrame)'
    JS: [Vue warn]: Error compiling template:
    JS:
    JS: App.html
    JS:
    JS: - Component template requires a root element, rather than just text.
    JS:
    JS:
    JS: found in
    JS:
    JS: ---> <App>
    JS:        <Frame>
    JS:          <Root>
    JS: [Vue warn]: Unknown custom element: <div> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
    

    类型脚本文件:app.ts

    import Vue from 'vue';
    import Component from 'vue-class-component';
    @Component({ template: 'App.html' })
    export default class App extends Vue {
        msg = 'Hello TS World!';
    }
    

    模板:app.html

    <template>
        <Page>
            <ActionBar title="Welcome to NativeScript-Vue!"/>
            <GridLayout columns="*" rows="*">
                <Label class="message" :text="msg" col="0" row="0"/>
            </GridLayout>
        </Page>
    </template>
    

    应用程序中还没有其他模板。如果我将它们作为一个单独的文件放在一起,就可以:

    谢谢!

    0 回复  |  直到 6 年前