[英]How can I get the data in Vue from Node.js
index.js索引.js
router.get('/', (req, res) => {
var cart = req.cookies.cart;
res.sendFile(path.join(__dirname,'../../src/components/cart.html'),cart);
})
cart.html购物车.html
<body>
<div id="app" class="container mt-3">
<h2> cart View </h2>
</div>
</body>
<script>
new Vue({
el: '#app',
data: {
}
})
</script>
I want to get cookies in vue..我想在 vue 中获取 cookie ..
How to get 'cart' data in Vue ?如何在 Vue 中获取“购物车”数据?
Is that right way make res.send('../cart.html',cart)
?这是正确的方法 make
res.send('../cart.html',cart)
吗?
You have to do request from vue to your server to fetch the data.您必须从 vue 向您的服务器发出请求以获取数据。 You can use axios for that.
你可以使用axios 。
BUT in this case you are sending cookies to server and trying to return cookies from request, why?但是在这种情况下,您将 cookie 发送到服务器并尝试从请求中返回 cookie,为什么? You can take your cookies on front-end without any request, use js-cookie .
您可以在没有任何请求的情况下在前端获取 cookie,使用js-cookie 。
Cookie.get('cart')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.