我正在跟随这个例子
我正在尝试使用vue.js加载一个html文件并添加到我的模板中。
我的尝试:
HTTML:
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/Static/content/css/foundation.css">
<link rel="stylesheet" type="text/css" href="/Static/content/css/spaceGame.css">
</head>
<body>
<div id="app">
<div class="grid-container">
<div class="grid-x grid-padding-x">
<div class="large-12 cell">
<h1>Welcome to Foundation</h1>
</div>
</div>
</div>
<div class="grid-x grid-padding-x">
<div class="large-4 columns"></div>
<div class="large-8 columns">
<component :is="currentView"></component>
</div>
</div>
</div>
<!-- Footer -->
<script src="https://unpkg.com/vue"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="/Static/scripts/foundation.js"></script>
<script type="text/javascript" src="/Static/scripts/what-input.js"></script>
<script type="text/javascript" src="/Static/scripts/space.js"></script>
</body>
</html>
脚本:
$(function() {
$(document).foundation()
var myData = '../../Views/login.html';
Vue.component('manage-posts', {
template: myData,
})
Vue.component('create-post', {
template: '#create-template'
})
new Vue({
el: '#app',
data: {
currentView: 'manage-posts'
}
})
});
错误:
我收到了以下内容:
- 组件模板需要一个根元素,而不只是文本。
将 var myData = '../../Views/login.html';
更改为:
var myData = '<div>../../Views/login.html</div>';
解决了错误,但是...我该如何加载实际的HTML文件?
我是单页应用程序和Vue.js的新手,已经花了一些时间,但还是无法解决。
编辑:
我要加载的HTML文件:
<div>
<template id="manage-template">
<form>
<div class="sign-in-form">
<h4 class="text-center">Sign In</h4>
<label for="sign-in-form-username">Username</label>
<input type="text" class="sign-in-form-username" id="sign-in-form-username">
<label for="sign-in-form-password">Password</label>
<input type="text" class="sign-in-form-password" id="sign-in-form-password">
<button type="submit" class="sign-in-form-button">Sign In</button>
</div>
</form>
</template>
</div>
编辑2:
如果这对答案有任何影响,我想指出:使用VS Code,站点正在运行IIS,这里没有使用node.js。