Typescript 未能装载组件:未定义模板或渲染函数:Vue动态导入,延迟加载
我得到以下错误。还有许多其他“视觉上”类似的问题。但我无法理解这些。我正在使用网页包。此模板由microsoft的javascriptservices模板生成。我对它们进行了修改,使它们能够与动态模板导入一起工作Typescript 未能装载组件:未定义模板或渲染函数:Vue动态导入,延迟加载,typescript,webpack,vue.js,Typescript,Webpack,Vue.js,我得到以下错误。还有许多其他“视觉上”类似的问题。但我无法理解这些。我正在使用网页包。此模板由microsoft的javascriptservices模板生成。我对它们进行了修改,使它们能够与动态模板导入一起工作 [Vue warn]: Failed to mount component: template or render function not defined. vendor.js?v=MxNIG8b0Wz6QtAfWhyA0-4CCwZshMscBGmtIBXxKshw:13856
[Vue warn]: Failed to mount component: template or render function not defined.
vendor.js?v=MxNIG8b0Wz6QtAfWhyA0-4CCwZshMscBGmtIBXxKshw:13856
found in
---> <MenuComponent>
<T> at ClientApp\components\app\app.vue.html
<Root>
warn @ vendor.js?v=MxNIG8b0Wz6QtAfWhyA0-4CCwZshMscBGmtIBXxKshw:13856
我的app.vue.html如下所示:
<template>
<div id='app-root' class="container-fluid">
<div class="row">
<div class="col-sm-3">
<menu-component />
</div>
<div class="col-sm-9">
<router-view></router-view>
</div>
</div>
</div>
</template>
<script src="./app.ts"></script>
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
@Component({
components: {
MenuComponent: require('../navmenu/navmenu.vue.html')
}
})
export default class AppComponent extends Vue {
}
[更新]
伙计们。现在我通过以下改变解决了这个问题
缺少一个位置。默认值在require之后。那是在boot.ts中
也可代替以下内容:
import('./components/counter/counter')
import('./components/counter/counter')
我不得不写下:
import('./components/counter/counter').then(m => m.default)
import('./components/counter/counter').then(m => m.default)
现在的问题是为什么这是一个问题?
我有
vue:^2.5.16,
vue加载程序:^14.2.2,
vue路由器:^3.0.1
下面的链接说,对于这些版本,如果我没有错的话,这些默认的相关更改是不需要的
而不是以下内容:
import('./components/counter/counter')
import('./components/counter/counter')
我不得不写下:
import('./components/counter/counter').then(m => m.default)
import('./components/counter/counter').then(m => m.default)
现在的问题是为什么这是一个问题
我有
vue:^2.5.16,
vue加载程序:^14.2.2,
vue路由器:^3.0.1。
由于esModule选项在新版本中为true,因此默认值为
您可以使用.default,也可以通过在vue加载程序选项中显式使用esModule:false来关闭新行为
例如:
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
},
esModule: false // example of setting to false
}
},
这些可以从Web包中配置。因此,它也适用于vue.html文件。问题在于动态导入。是的,可以进行配置。你没提到,很高兴知道你配置了它。我已经更新了答案。现在我来谈谈默认设置。我们添加了如何将esModule设置为false的示例。之所以使用.default属性,是因为当您导出默认内容时,该内容在导入'module'.default'中变为可用。