搭建微信小程序系列随机一句诗和图片防ONCE

搭建微信小程序系列随机一句诗和图片防ONCE

概况

运行效果

运行效果

后端

后端使用随便一个php站点,服务器使用阿里云腾讯云、百度云都可以。

推荐使用宝塔搭建,使能ssl.

代码下载: https://gitee.com/tui.guige/once/tree/master
backend 后端php代码

前端

前端使用uni-app ,新建一个项目,模板使用默认即可:
基本目录结构

项目目录结构
文件:config.js

export default{
	baseUrl: "填写你自己站点的路径"
}

文件: index.vue

<template>
	<view class="content">
		<image class="logo" :src=img_url></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<view class="text-area">
			<text class="source">{{source}}</text>
		</view>
	</view>
</template>

<script>
	
	import config from '@/common/config.js';
	
	export default {
		data() {
			return {
				title: 'ONCE-DEMO',
				img_url: '',
				source: '作者'
			}
		},
		onLoad() {
			uni.request({
				url: config.baseUrl + 'site.php',
				data: {
					'id': 'Your ID 推荐使用QQ号 或者手机号'
				},
				header: {
					'content-type': "application/x-www-form-urlencoded"
				},
				method:"POST",
				success: (res) => {
					//console.log(res.data)
					var res_data = res.data.data;
					if(res_data.code !== 1) { //如果请求失败,不等于1状态码
					    this.title = res_data.msg;
						return uni.showToast({
							title:"请求失败!"
						})
					}
					//数据请求成功
					this.title = res_data.content;
					this.img_url = res_data.img;
					this.source = res_data.source;
				}
				
			})
		},
		methods: {

		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 320rpx;
		width: 480rpx;
		margin-top: 150rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
	
	.source {
		font-size: 30rpx;
		color: #8f8f94;
		text-align: right;
	}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tui_GuiGe

鼓励一下作者吧,请他喝一瓶啤酒

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值