当前位置:网站首页>Record the creation process of a joke widget (II)

Record the creation process of a joke widget (II)

2022-06-24 03:28:00 leo689

Record the whole process of creating a joke widget ( Two )

The joke widget is really good - A sneak peek

Welcome to scan the yard and watch , Welcome to sesame joke applet ! thank you !

Insert picture description here

home page

The home page contains functions :

  • Display content list
  • Click for details
  • give the thumbs-up
  • Click on the upper right corner to share the entire applet
  • Share individual content

Display content list

Technical point

  • v-for Cyclic instruction
  • uni-card Card components

Technical realization

introduce uni-card Card components

<view class="example-body">
	<uni-card :isShadow="true" :title=item.title mode="title" thumbnail="/static/zhimaxiaohua.png" note="true"
		@click="">
		<view>
			<view class="content-box">
				<text class="content-box-text"> Card content </text>
			</view>
		</view>
		<template v-slot:footer>
			<view class="footer-box">
				<view class="applause" @click="footerClick(' like ')">
					<text> like </text>
				</view>
			</view>
		</template>
	</uni-card>
</view>

introduce v-for Cyclic instruction

<view v-for="(item,index) in dataList">
	
</view>

Sample data display

<template>
	<view>
		<view v-for="(item,index) in dataList">
			<view class="example-body">
				<uni-card :isShadow="true" :title=item.title mode="title" thumbnail="/static/zhimaxiaohua.png"
					note="true" @click="">
					<view>
						<view class="content-box">
							<text class="content-box-text">{{item.content}}</text>
						</view>
					</view>
					<template v-slot:footer>
						<view class="footer-box">
							<view class="applause" @click="footerClick(' like ')">
								<text> like </text>
							</view>
						</view>
					</template>
				</uni-card>
			</view>
		</view>
	</view>
</template>
<script>
	import indexJokeJsonData from "@/mockdata/index-jokes.json"
	export default {
		data() {
			return {
				dataList: indexJokeJsonData
			}
		}
	}
</script>

Mock Of json data

index-jokes.json

	[
		{
			"id": 1,
			"title": " Sesame joke ",
			"content": " This is the content "
		},
		{
			"id": 2,
			"title": " Sesame joke ",
			"content": " This is the content "
		},
		{
			"id": 3,
			"title": " Sesame joke ",
			"content": " This is the content "
		}

	]

Click for details

Click to view details , It will jump to the details page , Jump will carry relevant parameters , such as id.

Click event function :@click="viewDetail(index)"

methods: {
			viewDetail: function(index) {
				uni.navigateTo({
					url: '/pages/joke-detail/joke-detail?index=' + index + '&dataSource=indexJokes'
				})
			}
}

Detail page receiving function , You need to create a joke-detai.vue file

<template>
	<view>
		<view class="content-box">
			<view class="head">
				<text>{{list[index].title}}</text>
			</view>
			<text class="content-box-text">
				{{list[index].content}}
			</text>
		</view>
	</view>
</template>
<script>
import indexJokeJsonData from "@/mockdata/index-jokes.json"
	
	export default {
		data() {
			return {
				list: indexJokeJsonData,
				index: 0
			}
		},
		
		onLoad: function(option) {
			this.index = option.index;
			var dataSourceParam = option.dataSource;
			
			if(dataSourceParam==='indexJokes') {
				this.list=indexJokeJsonData
			}
			
		}
	}
</script>

give the thumbs-up

footerClick(types) {
				uni.showToast({
					title: types,
					icon: 'none'
				})
			}

Click on the upper right corner to share the entire applet

Share individual content

These two parts will be put into a special account about the sharing function of wechat applet

Style rollup

index.vue Home page style

<style lang="scss">

	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		padding: 1px 0;
	}

	.example-box {
		margin: 12px 0;
	}

	.image-box {
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		height: 350rpx;
		overflow: hidden;
	}

	.image {
		/* #ifndef APP-NVUE */
		width: 100%;
		height: 100%;
		/* #endif */
		flex: 1;
	}

	.content-box {
		padding-top: 20rpx;
	}

	.content-box-text {
		font-size: 14px;
		line-height: 22px;
	}

	.footer-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: space-between;
		flex-direction: row;
	}

	.footer-box__item {
		align-items: center;
		padding: 1px 0;
		font-size: 12px;
		color: #666;
	}

	.applause image {
		width: 60rpx;
		height: 60rpx;
	}

	button::after {
		border: none;
	}

	.applause button {
		background-color: #FFFFFF;
	}
</style>

Record the whole process of creating a joke widget ( One )

Insert picture description here
原网站

版权声明
本文为[leo689]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/10/20211003163811152t.html