-
ArthurSlog
-
SLog-15
-
1 Year,
-
Through China,
-
July 18th 2018
Standing at the crossroads of The Times, the winner will be the most unafraid to learn and accept new things
Development Environment MacOS(High Sierra 10.13.5)
Required information and information sources:
-
All source code addresses for this article
-
Vue. Js template directive (Directive), currently (2018/7/17) there are 13, respectively:
-
v-text
-
v-html
-
v-show
-
v-if
-
v-else
-
v-else-if
-
v-for
-
v-on
-
v-bind
-
v-model
-
v-pre
-
v-cload
-
v-once
- Vue.js template directives are similar to programming language “keywords” or “reserved words”, such as if (judge statement keyword), for (loop statement keyword).
Start coding
- First, set up the static server and switch to the desktop path
cd ~/Desktop
- Create a folder node_vue_directive_LEARningLoad
mkdir node_vue_directive_learningload
- Switch to the new folder
cd node_vue_directive_learningload
- Use NPM to initialize the Node environment, press Enter to complete the initialization
npm init
- Install KOA and KOA-static using NPM
sudo npm install koa koa-static
- With reference to the KOA-static instruction manual, we write two files index.js and index. HTML under the current path
index.js
const serve = require('koa-static');
const Koa = require('koa');
const app = new Koa();
// $ GET /package.json
app.use(serve('. '));
app.listen(3000);
console.log('listening on port 3000');
Copy the code
index.html
<html>
<head>
<meta charset="utf-8">
<title>ArthurSlog</title>
</head>
<body>
<h1>The static web server by ArthurSlog</h1>
</body>
</html>
Copy the code
- Next, we will write the vue.js template instruction code according to the use scenario
v-else.html
<html>
<head>
<meta charset="utf-8">
<! -- Development environment version, including helpful command line warnings -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<title>ArthurSlog</title>
</head>
<body>
<div id="app">
<h1 v-if="state1 === state2">Hello ArthurSlog, "state1" === "state2"</h1>
<h1 v-else>Hello ArthurSlog, "state1" ! == "state2"</h1>
</div>
<script>
new Vue({
el: '#app',
data: {
state1: 'ok',
state2: 'no'}})</script>
</body>
</html>
Copy the code
-
Now you can open your browser, type 127.0.0.1:3000/ V-else. HTML in the address bar, and you’ll see: Hello ArthurSlog, “state1”! == “state2”, the value of state1 is not equal to the value of state2, so the second string is displayed
-
So far, we have introduced the VUE template instruction V-else again, for more information, please refer to the vUE official manual.