如何在Vuejs的兄弟姐妹之间通过Bata
我正在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在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.