Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express : res.render(...,{...})时导入的数据怎么在一般js中使用。 #4

Open
zjutszl opened this issue Oct 25, 2017 · 3 comments

Comments

@zjutszl
Copy link
Contributor

zjutszl commented Oct 25, 2017

view/post.ejs

<!DOCTYPE html>
<html>

<head lang="en">
  <meta charset="UTF-8">
  <title>cnode·Supported by Vue</title>
</head>

<body>
<% var postId = _id %>

<h1>_id : <%= _id %></h1>
<p>postId : <%= postId %></p>
<div id="app">
<h1>{{ detailData.content }}</h1>
<p>{{ post_id }}</p>

</div>
</body>

<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript">
var postId = '12345654321';
var app = new Vue({
    el: "#app",
    data: {
      detailData : {
      	content:'zjutszl'
      },
      post_id:postId
    }
})
</script>

</html>

routes/post.js

var express = require('express');
var router = express.Router();

/* GET users listing. */
router.get('/', function (req, res, next) {
    res.render('post_detail', {_id:req.query.id});
});


module.exports = router;

页面显示

alt

添加一行定义 [var postId = '12345654321']

alt

修改后页面显示

alt


为了阅读方便,先放了代码,图片在后面。

@zjutszl
Copy link
Contributor Author

zjutszl commented Oct 25, 2017

那么问题来了,怎么在Vue里用到routes/post.js传入的数据:_id 呢?

@zjutszl
Copy link
Contributor Author

zjutszl commented Oct 25, 2017

alt
alt

@xugy0926
Copy link
Owner

参考 18-edit-post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants