如何在Vuejs的兄弟姐妹之间通过Bata

发布于 2025-01-22 09:17:55 字数 801 浏览 1 评论 0原文

我正在Vuejs创建购物车。我的标题中有购物车图标,而我的产品中有另一个组件。我需要将一系列产品带入标头的内部,以便我可以将靠近购物车图标的长度打印出来。这里有一些代码:

data: () => {
    return {
        cart: [],
        products: [
            {
                name: "Margherita",
                price: 5,
                image: "https://www.scattidigusto.it/wp-content/uploads/2018/03/pizza-margherita-originale-Scatti-di-Gusto-1568x821.jpg"
            },
            {
                name: "Marinara",
                price: 4,
                image: "https://wips.plug.it/cips/buonissimo.org/cms/2012/05/pizza-marinara-5.jpg"
            },
            {
                name: "Diavola",
                price: 6,
                image: "https://www.coopshop.it/p/wp-content/uploads/2021/02/Salame_940x450.jpg"
            }
        ]
    }

I'm creating a shopping cart in VueJS. I have the cart icon in the header and my products in another component. I need to take the array of products inside of the header so i can print the length near to the cart icon. Here some code:

data: () => {
    return {
        cart: [],
        products: [
            {
                name: "Margherita",
                price: 5,
                image: "https://www.scattidigusto.it/wp-content/uploads/2018/03/pizza-margherita-originale-Scatti-di-Gusto-1568x821.jpg"
            },
            {
                name: "Marinara",
                price: 4,
                image: "https://wips.plug.it/cips/buonissimo.org/cms/2012/05/pizza-marinara-5.jpg"
            },
            {
                name: "Diavola",
                price: 6,
                image: "https://www.coopshop.it/p/wp-content/uploads/2021/02/Salame_940x450.jpg"
            }
        ]
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼亦尘 2025-01-29 09:17:55

您应该在Vuex商店内存储产品列表。从那里,列表将可用于您的应用程序中的每个组件。

You should store the list of products inside your Vuex store. From there the list will be available to each and every component in your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文