简体   繁体   中英

How can I get the data in Vue from Node.js

index.js

router.get('/', (req, res) => {
    var cart = req.cookies.cart;
    res.sendFile(path.join(__dirname,'../../src/components/cart.html'),cart);
})

cart.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..

How to get 'cart' data in Vue ?

Is that right way make res.send('../cart.html',cart) ?

You have to do request from vue to your server to fetch the data. You can use axios for that.

BUT in this case you are sending cookies to server and trying to return cookies from request, why? You can take your cookies on front-end without any request, use js-cookie .

Cookie.get('cart')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM