簡體   English   中英

Typescript Vue:無法安裝組件:模板或渲染 function 未定義

[英]Typescript Vue: Failed to mount component: template or render function not defined

大家我想將 typescript 添加到我的 vue 項目中,現在它編譯沒有錯誤,但是一旦我打開頁面,控制台中就會出現一條錯誤消息:

vue.runtime.esm.js?2b0e:619 [Vue warn]: Failed to mount component: template or render function not defined.

found in

---> <App> at src/App.vue
       <Root>

這是我的main.ts

import Vue from 'vue'
import App from './App.vue'
import router from './router/router'
import store from './store/store'

// @ts-ignore
import VueFormulate from '@braid/vue-formulate'

import api from './api/api'

import './assets/scss/app.scss'

import './registerServiceWorker.ts'

Vue.config.productionTip = false
// @ts-ignore
Vue.$api = api;
Object.defineProperty(Vue.prototype, '$api', {
    get() {
        return api
    }
})

Vue.use(VueFormulate)

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')

而這是我的App.vue是的,安裝了vue-class-components

<template>
    <div class="container-fluid container-lg container-xl" id="app">
        <router-view></router-view>
    </div>
</template>

<script lang="ts">

import Component from "vue-class-component";
import Vue from "vue";

@Component
export default class App extends Vue{
    created(){
        console.log("foo");
    }
}

</script>

我實際上直接從文檔中復制了組件的結構,所以我假設我的錯誤一定在我的main.ts中的某個地方。 另請注意,它是一個 vue2 項目,所以 vue3 沒有問題。

事實上,顯示的配置並沒有錯。 我重新創建了一個最小的工作示例,復制了完全相同的文件,但它仍然無法正常工作。

工具鏈中的某處配置錯誤,我使用 vue cli 重新安裝了項目,將原始文件復制回來,一切正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM