【发布时间】:2019-11-10 16:27:11
【问题描述】:
我正在尝试实现一个外部模板(创建一个 HTML 页面),但我无法成功。此页面是一个包含 Vue 应用程序的 ASP.NET MVC 页面。
我想将此组件的 template 部分移动到外部文件中,但每当我这样做时,它都不起作用。
以下(下)确实有效,但由于失去了文本编辑功能,维护或构建并不容易。
Vue.component('我的组件', { 模板:'#my-component' }
这是当前的代码,它运行良好:
var foo = Vue.component('foo', {
template:'
<table class="table">
<template v-for="(foo, ColName, index) in foos">
<template v-if="index % 3 == 0">
<tr>
</tr>
</template>
<th>{{ColName}}</th>
<td v-if="foo">{{foo}}</td>
<td v-else> -- </td>
</template>
</table>',
data: function () {
return {
foos: null,
NumColuns: 3
}
},
mounted() {
axios
.get('/api/account/foo/')
.then(response => {
this.foos = response.data
})
.catch(error => {
console.log(error1)
this.errored = true
})
.finally(() => this.loading = false)
}
});
var foo = new Vue({
el: '#foo-vue'
});
【问题讨论】:
-
#my-component 表示模板位于该页面的 HTML 中。根据您的解释,尚不清楚 Vue 代码是在该页面上还是在其他文件上,或者到底是什么。您能否明确说明其中包含哪些文件?
-
我认为他在一个 JS 文件中包含所有内容,包括模板,并且他从 HTML 页面引用该模板。他希望将模板放在单独的文件中。
-
我所有的代码都在JS页面上,我想把它分离成一个HTML页面(模板)。
标签: javascript asp.net-mvc vue.js