用vue.js设计一个Web前端程序作品,要求至少包括首页、类目页、详情页、订单页、注册/登录页等

时间: 2023-08-12 16:06:10 浏览: 51
好的,以下是一个简单的基于Vue.js的Web前端程序作品示例,包括首页、类目页、详情页、订单页、注册/登录页等: 1. 首页 ```html <template> <div> <h1>欢迎来到我的商城!</h1> <p>这里有各种商品供您选择购买。</p> <ul> <li v-for="item in products" :key="item.id"> <router-link :to="'/product/' + item.id">{{ item.name }}</router-link> </li> </ul> </div> </template> <script> export default { data() { return { products: [ { id: 1, name: '商品1', price: 10 }, { id: 2, name: '商品2', price: 20 }, { id: 3, name: '商品3', price: 30 } ] } } } </script> ``` 2. 类目页 ```html <template> <div> <h1>{{ category }}</h1> <p>这里有属于{{ category }}类别的商品。</p> <ul> <li v-for="item in products" :key="item.id"> <router-link :to="'/product/' + item.id">{{ item.name }}</router-link> </li> </ul> </div> </template> <script> export default { data() { return { category: '电子产品', products: [ { id: 1, name: '手机', price: 2000 }, { id: 2, name: '电脑', price: 5000 }, { id: 3, name: '平板', price: 3000 } ] } } } </script> ``` 3. 详情页 ```html <template> <div> <h1>{{ product.name }}</h1> <p>价格:{{ product.price }}元</p> <button @click="addToCart">加入购物车</button> </div> </template> <script> export default { data() { return { product: null } }, mounted() { // 从API获取商品信息 axios.get('/api/product/' + this.$route.params.id) .then(response => { this.product = response.data }) .catch(error => { console.log(error) }) }, methods: { addToCart() { // 添加商品到购物车 console.log('添加成功!') } } } </script> ``` 4. 订单页 ```html <template> <div> <h1>我的订单</h1> <ul> <li v-for="item in orders" :key="item.id"> {{ item.product }} - {{ item.price }}元 </li> </ul> <button @click="placeOrder">下单</button> </div> </template> <script> export default { data() { return { orders: [ { id: 1, product: '商品1', price: 10 }, { id: 2, product: '商品2', price: 20 }, { id: 3, product: '商品3', price: 30 } ] } }, methods: { placeOrder() { // 提交订单 console.log('下单成功!') } } } </script> ``` 5. 注册/登录页 ```html <template> <div> <h1>注册/登录</h1> <form> <label for="username">用户名:</label> <input type="text" id="username" v-model="username"> <br> <label for="password">密码:</label> <input type="password" id="password" v-model="password"> <br> <button type="submit" @click.prevent="submitForm">提交</button> </form> <div v-if="message">{{ message }}</div> </div> </template> <script> export default { data() { return { username: '', password: '', message: '' } }, methods: { submitForm() { // 发送登录/注册请求 axios.post('/api/login', { username: this.username, password: this.password }) .then(response => { // 登录/注册成功 this.message = '登录/注册成功!' // 存储token localStorage.setItem('token', response.data.token) // 跳转到首页 this.$router.push('/') }) .catch(error => { // 登录/注册失败 this.message = '登录/注册失败,请检查用户名和密码!' console.log(error) }) } } } </script> ``` 注意:以上示例中涉及到的API请求需要根据实际情况进行编写,同时需要使用Vue Router进行页面路由控制。

最新推荐

recommend-type

vue如何通过id从列表页跳转到对应的详情页

主要介绍了vue如何通过id从列表页跳转到对应的详情页 ,需要的朋友可以参考下
recommend-type

vue中使用vue-print.js实现多页打印

本文主要介绍了vue项目中使用print.js打印,解决多页,分页,打印预览样式修改等问题。 引入安装vue-print.js cnpm i vue-printjs --save-dev 解决打印多页只出现一页问题 由于打印插件存在问题,如果打印文件...
recommend-type

vue页面跳转后返回原页面初始位置方法

vue页面跳转到新页面之后,再由新页面返回到原页面时候若想返回调出原页面的初始位置,怎么来解决这个问题呢?首先我们应该在跳出页面时候记录下跳出的scrollY,返回原页面的时候在设置返回位置为记录下的scrolly...
recommend-type

vue写h5页面的方法总结

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

利用Vue.js+Node.js+MongoDB实现一个博客系统(附源码)

本文主要介绍了利用Vue.js+Node.js+MongoDB实现一个博客系统,这个博客使用Vue做前端框架,Node+express做后端,数据库使用的是MongoDB。实现了用户注册、用户登录、博客管理、文章编辑、标签分类等功能,需要的朋友...
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

【实战演练】MATLAB用遗传算法改进粒子群GA-PSO算法

![MATLAB智能算法合集](https://static.fuxi.netease.com/fuxi-official/web/20221101/83f465753fd49c41536a5640367d4340.jpg) # 2.1 遗传算法的原理和实现 遗传算法(GA)是一种受生物进化过程启发的优化算法。它通过模拟自然选择和遗传机制来搜索最优解。 **2.1.1 遗传算法的编码和解码** 编码是将问题空间中的解表示为二进制字符串或其他数据结构的过程。解码是将编码的解转换为问题空间中的实际解的过程。常见的编码方法包括二进制编码、实数编码和树形编码。 **2.1.2 遗传算法的交叉和
recommend-type

openstack的20种接口有哪些

以下是OpenStack的20种API接口: 1. Identity (Keystone) API 2. Compute (Nova) API 3. Networking (Neutron) API 4. Block Storage (Cinder) API 5. Object Storage (Swift) API 6. Image (Glance) API 7. Telemetry (Ceilometer) API 8. Orchestration (Heat) API 9. Database (Trove) API 10. Bare Metal (Ironic) API 11. DNS
recommend-type

JSBSim Reference Manual

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