Html 除非我延迟JavaScript文件链接,否则Vue胡子模板无法工作
我正在开发一个简单的Vue应用程序。根据脚本在头部的位置以及是否使用了延迟,我体验到了不同的结果。如果没有延迟,则胡须模板在没有Vue的情况下按原样呈现(例如,Html 除非我延迟JavaScript文件链接,否则Vue胡子模板无法工作,html,vue.js,vuejs2,Html,Vue.js,Vuejs2,我正在开发一个简单的Vue应用程序。根据脚本在头部的位置以及是否使用了延迟,我体验到了不同的结果。如果没有延迟,则胡须模板在没有Vue的情况下按原样呈现(例如,{{playerHealth},而不是Vue数据中分配给它的数字),但是如果我将延迟添加到app.js链接(跟随Vue CDN链接),它将正常呈现 以HTML格式呈现的胡须模板: <head> <meta charset="utf-8"> <meta name="viewport" content="
{{playerHealth}
,而不是Vue数据中分配给它的数字),但是如果我将延迟添加到app.js链接(跟随Vue CDN链接),它将正常呈现
以HTML格式呈现的胡须模板:
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demon Slayer</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
<script src="app.js"></script>
<!-- Only using CSS for Foundation, no JS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.3/dist/css/foundation.min.css" integrity="sha256-xpOKVlYXzQ3P03j397+jWFZLMBXLES3IiryeClgU5og= sha384-gP4DhqyoT9b1vaikoHi9XQ8If7UNLO73JFOOlQV1RATrA7D0O7TjJZifac6NwPps sha512-AKwIib1E+xDeXe0tCgbc9uSvPwVYl6Awj7xl0FoaPFostZHOuDQ1abnDNCYtxL/HWEnVOMrFyf91TDgLPi9pNg==" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Metamorphous|Raleway&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/app.css">
</head>
HTML
您需要将app.js添加到标记的末尾,而不是标记的末尾。添加“延迟”属性可以模拟此行为。请参阅更多信息:在头部使用带有延迟的脚本比在正文末尾包含脚本要快,因为脚本是异步下载的。您需要将app.js添加到标记的末尾,而不是标记的末尾。添加“延迟”属性可以模拟此行为。请参阅更多信息:在头部使用带有延迟的脚本比在正文末尾包含脚本要快,因为脚本是异步下载的。
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
<script defer src="app.js"></script>
new Vue({
el: '#app',
data: {
playerHealth: 100,
demonHealth: 100,
gameIsRunning: false
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Demon Slayer</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.0"></script>
<script defer src="app.js"></script>
<!-- Only using CSS for Foundation, no JS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.3/dist/css/foundation.min.css" integrity="sha256-xpOKVlYXzQ3P03j397+jWFZLMBXLES3IiryeClgU5og= sha384-gP4DhqyoT9b1vaikoHi9XQ8If7UNLO73JFOOlQV1RATrA7D0O7TjJZifac6NwPps sha512-AKwIib1E+xDeXe0tCgbc9uSvPwVYl6Awj7xl0FoaPFostZHOuDQ1abnDNCYtxL/HWEnVOMrFyf91TDgLPi9pNg==" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Metamorphous|Raleway&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<div id="app" class="grid-container">
<h1>DEMON SLAYER</h1>
<section class="grid-x">
<div class="cell small-6">
<h2>YOU</h2>
<div class="health-bar">
<div class="health-bar" style="background-color: green; margin: 0; color: white;">
{{ playerHealth }}
</div>
</div>
</div>
<div class="cell small-6">
<h2>DEMON</h2>
<div class="health-bar">
<div class="health-bar" style="background-color: green; margin: 0; color: white;">
{{ demonHealth }}
</div>
</div>
</div>
</section>
<section class="cell controls">
<button id="start-game">NEW GAME</button>
</section>
<section class="cell controls">
<button id="attack">ATTACK</button>
<button id="special-attack">SPECIAL ATTACK</button>
<button id="heal">HEAL</button>
<button id="give-up">GIVE UP</button>
</section>
<section class="cell log">
<ul>
<li>
</li>
</ul>
</section>
</div>
</body>
</html>
body {
font-family: "Raleway", sans-serif;
text-align: center;
letter-spacing: 2px;
}
h1 {
font-family: "Metamorphous", cursive;
letter-spacing: 3px;
margin-top: 0.8rem;
font-size: 2.5rem;
}
h2 {
font-size: 1.5rem;
}
.health-bar {
width: 80%;
height: 40px;
background-color: #eee;
margin: auto;
transition: width 500ms;
}
.controls, .log {
margin-top: 30px;
padding: 10px;
border: 1px solid #ccc;
box-shadow: 0 3px 6px #ccc;
}
.turn {
margin-top: 20px;
margin-bottom: 20px;
font-weight: bold;
font-size: 22px;
}
.log ul {
list-style: none;
font-weight: bold;
text-transform: uppercase;
}
.log ul li {
margin: 5px;
}
.log ul .player-turn {
color: blue;
background-color: #e4e8ff;
}
.log ul .monster-turn {
color: red;
background-color: #ffc0c1;
}
button {
font-size: 20px;
background-color: #eee;
padding: 12px;
box-shadow: 0 1px 1px black;
margin: 10px;
}
button:hover {
cursor: pointer;
}
#start-game {
background-color: #7ad47a;
}
#start-game:hover {
background-color: #6cc56c;
}
#attack {
background-color: #ff7367;
}
#attack:hover {
background-color: #ff3f43;
}
#special-attack {
background-color: #ffaf4f;
}
#special-attack:hover {
background-color: #ff9a2b;
}
#heal {
background-color: #87cefa;
}
#heal:hover {
background-color: #76bde9;
}
#give-up {
background-color: #dbdbdb;
}
#give-up:hover {
background-color: #acacac;
}