小程序开发之路uni-app 活动

108 阅读1分钟

「这是我参与2022首次更文挑战的第20天,活动详情查看:2022首次更文挑战

基于uni-app对vue3的支持不是很完善,开发中使用vue2。

java jdk已更新到17,实际使用中大部分还是使用1.8。

创建UniApp项目

配置文件 pages.json

页面配置

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/home/home",
			"style": {
				"navigationBarTitleText": "uni-app"
			}
		}
        ,{
            "path" : "pages/activity/activity",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/user/user",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/activity/activity-detail",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "",
                "enablePullDownRefresh": false
            }
            
        }
    ],
	
	
}

全局样式配置

"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	},

下方工具栏配置

"tabBar": {
			"color": "#7A7E83",
			"selectedColor": "#007AFF",
			"borderStyle": "black",
			"backgroundColor": "#F8F8F8",
			"list": [
				{
					"pagePath": "pages/home/home",
					"iconPath": "static/tab-home.png",
					"selectedIconPath": "./static/tab-home-current.png",
					"text": "首页"
				},{
					"pagePath": "pages/activity/activity",
					"iconPath": "./static/tab-cate.png",
					"selectedIconPath": "./static/tab-cate-current.png",
					"text": "活动"
				},
				{
					"pagePath": "pages/user/user",
					"iconPath": "static/tab-my.png",
					"selectedIconPath": "./static/tab-my-current.png",
					"text": "我的"
				}
				
			]
		}

创建页面news

编写静态页面,获取后台数据后用 v-for渲染列表

<template>
	<view>
		<view class="news-item" @click="handleNewsItemClick">
			<view class="news-item-left">
				<image class="news-item-img" src="/static/temp/news1.png"></Image>
			</view>
		
			<view class="news-item-right">
				<view class="news-item-title">标题</view>
				<view class="news-item-context">文本内容”。</view>
				<view class="news-item-footer">2022-02-14</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			handleNewsItemClick(){
				uni.navigateTo({
					url: "./news-detail"
				})
			}
		}
	}
</script>

<style>

.news-item{
	display: flex;
	height: 200rpx;

	
}
.news-item-right{
	flex-direction: column;
	padding: 5rpx 20rpx;
	position: relative;
}
.news-item-left{
	width: 400rpx;
	
	padding: 5rpx 10rpx;
	
}
.news-item-img{
	width: 100%;
	height: 100%;
}
.news-item-title{
	font-weight: bold;
	font-size: 36rpx;
}
.news-item-context{
	font-size: 30rpx;
}
.news-item-footer{
	font-size: 26rpx;
	position: absolute;
	bottom: 0rpx;	
}

</style>

页面详情页

<template>
	<view>
		<rich-text :nodes="newsContext"></rich-text>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newsContext: '<p></p>'
			}
		},
		methods: {
			
		}
	}
</script>

<style>

</style>

此处使用了rich-text组件 node 使用HTML String渲染富文本。

创建活动页面

<template>
	<view>
		<view class="activity-item" @click="handleActivityItemClick">
			<view class="activity-item-context">
				<image class="activity-item-img" src="/static/temp/ad2.jpg"></Image>
			</view>
			<view class="activity-item-title">防疫宣讲活动</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			handleActivityItemClick(){
				uni.navigateTo({
					url: "./activity-detail"
				})
			}
		}
	}
</script>

<style>

.activity-item{

	position: relative;
}
.activity-item-context{
	width: 100%rpx;
	height: 220rpx;
	padding: 15rpx 30rpx;
	
}
.activity-item-img{
	width: 100%;
	height: 100%;
}
.activity-item-title{
	position: absolute;
	bottom: 30rpx;
	left: 30rpx;
	font-weight: bold;
	font-size: 36rpx;
	/* color: #FFFFFF; */
	padding-left: 30rpx;

}


</style>

活动详情

<template>
	<view>
		<view class="activity-item" @click="handleActivityItemClick">
			<view class="activity-item-context">
				<image class="activity-item-img" src="/static/temp/ad2.jpg"></Image>
			</view>
			<rich-text :nodes="activityContext"></rich-text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activityContext: '防疫宣讲活动'
			}
		},
		methods: {
			handleActivityItemClick(){
				uni.navigateTo({
					url: "./activity-detail"
				})
			}
		}
	}
</script>

<style>

.activity-item{

	position: relative;
}
.activity-item-context{
	width: 100%rpx;
	height: 220rpx;
	padding: 15rpx 30rpx;
	
}
.activity-item-img{
	width: 100%;
	height: 100%;
}
.activity-item-title{
	position: absolute;
	bottom: 30rpx;
	left: 30rpx;
	font-weight: bold;
	font-size: 36rpx;
	/* color: #FFFFFF; */
	padding-left: 30rpx;

}


</style>

总结 配置了基础的页面tabbar,实现了活动静态页面。