zoukankan      html  css  js  c++  java
  • 068——VUE中vuex的使用场景分析与state购物车实例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>vuex的使用场景分析与state购物车实例</title>
        <script src="vue.js"></script>
        <script src="vuex.js"></script>
    </head>
    <body>
    <div id="demo">
        <lists></lists>
    </div>
    <script type="text/x-template" id="lists">
        <div>
            <table>
                <tr><th>编号</th><th>名称</th><th>价格</th></tr>
                <tr v-for="v in goods">
                    <td>{{v.id}}</td>
                    <td>{{v.title}}</td>
                    <td>{{v.price}}</td>
                </tr>
            </table>
            <h1>总价:{{totalPrice}}</h1>
        </div>
    </script>
    <script>
        store = new Vuex.Store({
            state: {
                totalPrice: 100,
                goods: [
                    {id: 1, title: "iphone7Plus", price: 399},
                    {id: 2, title: "vivo20", price: 3909}
                ]
            }
        });
        let lists = {
            template: "#lists",
            computed: {
                totalPrice() {
                    return this.$store.state.totalPrice;
                },
                goods() {
                    return this.$store.state.goods;
                }
            }
        }
        new Vue({
            el: "#demo",
            store,
            components: {
                lists
            }
        });
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    1. 二分查找
    Filezilla使用
    正则表达式regex
    TCP的三次握手和四次挥手
    Pycharm 更换源
    寒假学习进度(十四)
    寒假学习进度(十)
    寒假学习进度(九)
    寒假学习进度(八)
    寒假学习进度(七)
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8371835.html
Copyright © 2011-2022 走看看