uni-app学习心得体会

本文分享了使用uni-app开发网上商城App的体验,包括首页、分类、购物车和我的页面的实现效果及功能。uni-app基于Vue.js,允许一套代码发布到多平台。优点在于统一开发、易上手和丰富的生态系统,但存在性能、体验和功能限制等挑战。适合有一定Vue.js基础的开发者使用。
摘要由CSDN通过智能技术生成

     uni-app是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS、Android、Web(响应式)、以及各种小程序(微信/支付宝/百度/头条/飞书/QQ/快手/钉钉/淘宝)、快应用等多个平台。

     在学习uniapp的过程中,我试着以node.js作为后端,开发了一个网上商城app。这个app底部Tabber有着四个功能页面:首页,分类,购物车,我的。

1.首页代码和实现效果

<template>
	<view class="shou">
		<scroll-view scroll-x="true" class="scroll-content" :scroll-into-view="scrollIndex">
			<view :id="'top'+index" class="scroll-item" v-for="(item,index) in topBar" :key="index"
				@tap='changeTab(index)'>
				<text :class="topBarIndex===index? 'f-active-color':'f-color'">{
  {item.name}}</text>
			</view>
		</scroll-view>

		<swiper @change="onChangeTab" :current="topBarIndex" :style="'height:'+clientHeight+'px;'">
			<swiper-item v-for="(item,index) in newTopBar" :key="index">

				<scroll-view scroll-y="true" :style="'height:'+clientHeight+'px;'" @scrolltolower='loadMore(index)'>
					<block v-if='item.data.length>0'>
						<block v-for="(k,i) in item.data" :key="i">

							<!-- //推荐 -->
							<swiperVue v-if="k.type=='swiperVue'" :dataList="k.data"></swiperVue>
							<template v-if="k.type=='recommendVue'">
								<recommendVue :dataList="k.data"></recommendVue>
								<cardVue cardTitle="猜你喜欢"></cardVue>
							</template>

							<!-- //其他 -->
							<Banner v-if="k.type=='Banner'" :dataList="k.imgUrl"></Banner>
							<template v-if="k.type=='Icons'">
								<Icons :dataList="k.data"></Icons>
								<cardVue cardTitle="热销爆品"></cardVue>
							</template>
							<template v-if="k.type=='Hot'">
								<Hot :dataList="k.data"></Hot>
								<cardVue cardTitle="为你推荐"></cardVue>
							</template>

							<commodityVue v-if="k.type=='commodityVue'" :dataList="k.data"></commodityVue>
						</block>
					</block>
					<view v-else>
						暂无数据...
					</view>
					<view class='load-text f-color'>
						{
  {item.loadText}}
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
<Tabbar cureentPage='HomePage'></Tabbar>
	</view>
</template>

<script>
	import recommendVue from '../../colorui/components/recommend.vue';
	import swiperVue from '../../colorui/components/swiper.vue';
	import cardVue from '../../colorui/components/Card.vue';
	import commodityVue from '../../colorui/components/CommodityList.vue';
	import Banner from '../../colorui/components/Banner.vue';
	import Icons from '../../colorui/components/Icons.vue';
	import Hot from '../../colorui/components/Hot.vue';
	import $http from '@/common/api/request.js';
	import Tabbar from '@/colorui/components/Tabbar.vue'
	export default {
		data() {
			return {
				//索引
				topBarIndex: 0,
				//顶栏滑动
				scrollIndex: 'top0',
				//内容块高度
				clientHeight: 0,
				//顶栏数据
				topBar: [],
				//承载数据
				newTopBar: []
			}
		},
		components: {
			swiperVue,
			recommendVue,
			cardVue,
			commodityVue,
			Banner,
			Icons,
			Hot,
			Tabbar
		},
		onLoad() {
			this.__init();
		},
		onReady() {
			uni.getSystemInfo({
				success: (res) => {
					this.clientHeight = res.windowHeight - this.getClientHeight();
				}
			})
		},
		onNavigationBarButtonTap(e) {
			if (e.float == 'left') {
				uni.navigateTo({
					url: "../search/search"
				})
			}
		},
		methods: {
			//请求首页数据10.92.12.23,192.168.2.213,localhost
			__init() {
				$http.request({
					url: "/index_list/data"
				}).then((res) => {
					this.topBar = res.topBar;
					this.newTopBar = this.initData(res);
				}).catch(() => {
					uni.showToast({
						title: '请求失败',
						icon: 'none'
					})
				})
			},
			//添加数据
			initData(res) {
				let arr = [];
				for (let i = 0; i < this.topBar.length; i++) {
					let obj = {
						data: [],
						load: "first",
						loadText: "上拉加载更多..."
					}
					//获取首次数据
					if (i == 0) {
						obj.data = res.data;
					}
					arr.push(obj)
				}
				return arr;
			},
			// goDetailPage(e) {
			// 	if (typeof e === 'string') {
			// 		uni.navigateTo({
			// 			url: '/pages/tabBar/' + e + '/' + e
			// 		});
			// 	} else {
			// 		uni.navigateTo({
			// 			url: e.url
			// 		});
			// 	}
			// },
			//点击顶栏
			changeTab(index) {
				if (this.topBarIndex === index) {
					return;
				}
				this.topBarIndex = index;
				this.scrollIndex = 'top&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值