提供用vue 前端框架写的类似 Microsoft Store界面源代码

时间: 2024-02-19 12:59:26 浏览: 23
好的,这里提供一个简单的源代码供参考: ```html <template> <div> <div class="header"> <h1>Microsoft Store</h1> <input type="text" v-model="searchText" placeholder="Search products..."> </div> <div class="products"> <div class="product" v-for="product in filteredProducts" :key="product.id"> <img :src="product.image" :alt="product.name"> <h2>{{ product.name }}</h2> <p>{{ product.price }}</p> <button @click="addToCart(product)">Add to cart</button> </div> </div> <div class="cart"> <h2>Cart</h2> <ul> <li v-for="item in cart" :key="item.id"> {{ item.name }} - {{ item.price }} </li> </ul> </div> </div> </template> <script> export default { data() { return { products: [ { id: 1, name: 'Product 1', price: '$10', image: 'product1.png' }, { id: 2, name: 'Product 2', price: '$20', image: 'product2.png' }, { id: 3, name: 'Product 3', price: '$30', image: 'product3.png' }, { id: 4, name: 'Product 4', price: '$40', image: 'product4.png' }, { id: 5, name: 'Product 5', price: '$50', image: 'product5.png' } ], cart: [], searchText: '' } }, computed: { filteredProducts() { return this.products.filter(product => { return product.name.toLowerCase().includes(this.searchText.toLowerCase()); }); } }, methods: { addToCart(product) { this.cart.push(product); } } } </script> <style> .header { display: flex; justify-content: space-between; align-items: center; padding: 20px; } .products { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); grid-gap: 20px; padding: 20px; } .product { display: flex; flex-direction: column; align-items: center; text-align: center; } .product img { width: 100%; max-width: 200px; height: auto; } .cart { padding: 20px; } .cart h2 { margin-bottom: 10px; } .cart ul { list-style: none; margin: 0; padding: 0; } .cart li { margin-bottom: 5px; } </style> ``` 这个示例代码中,我们使用了 Vue 的组件化开发方式,将整个页面拆分成多个组件,包括 header、products 和 cart 等。其中,products 组件用来展示所有的产品,并且可以根据用户输入的搜索文本进行过滤;cart 组件用来展示用户已经添加到购物车中的产品。 在 JavaScript 代码中,我们使用了 computed 属性来实现根据搜索文本进行过滤的功能,并且使用了 methods 属性来实现添加产品到购物车的功能。同时,我们还使用了 Vue 的双向绑定功能来实现搜索框的实时响应。 最后,我们使用了一些简单的 CSS 样式来美化页面,使得界面更加美观和易读。

相关推荐

最新推荐

recommend-type

Vue框架总结.pdf

的 Vue 项目中,使用得更多的是单文件组件。 单文件组件 每一个以 .vue 为后缀的文件,都是一个组件,称为“单文件组件”。 单文件组件由三部分组成: • &lt;template&gt;:组件模版,类似 HTML • [removed]:组件...
recommend-type

Vue前端开发规范整理(推荐)

本文是基于vue官方风格指南整理的关于Vue前端开发规范(推荐),非常不错,具有参考借鉴借鉴价值,需要的朋友可以参考下
recommend-type

vue使用canvas实现移动端手写签名

主要为大家详细介绍了基于vue使用canvas实现移动端手写签名,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

vue前端面试题汇总(常问-进阶篇)

vue中computed和watch的区别 1.computed的用法 是一个计算属性,类似于过滤器,对绑定到view的数据进行处理。computed上面的属性不可在vue data中声明,不能做异步处理 data: { firstName: 'Foo', lastName: 'Bar' ...
recommend-type

vue写h5页面的方法总结

下面就是小编带给大家的如何用vue写h5页面方法操作,希望能够给你们带来一定的帮助,谢谢大家的观看。 1、当拿到设计师给的UI设计图,前端的首要任务就是布局和样式,相信这对于大部分前端工程师来说已经不是什么...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。