-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
47 lines (40 loc) · 1011 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// npm install express
var express = require('express')
var expressVue = require('express-vue')
var app = express();
app.engine('vue', expressVue);
app.set('view engine', 'vue');
app.set('views', __dirname + '/views');
app.set('vue', {
componentsDir: __dirname + '/views/components',
defaultLayout: 'layout'
});
var users = [];
users.push({ name: 'tobi', age: 12 });
users.push({ name: 'loki', age: 14 });
users.push({ name: 'jane', age: 16 });
app.get('/', function(req, res){
res.render('index', {
data: {
title: 'Express Vue',
message: 'Hello!',
users: users
},
vue: {
components: ['users', 'message']
}
});
});
app.get('/users/:userName', function(req, res){
var user = users.filter(function(item) {
return item.name === req.params.userName;
})[0];
res.render('user', {
data: {
title: 'Hello My Name is',
user: user
}
});
});
app.listen(3000);
console.log('Express server listening on port 3000');