【大白话学习】UniApp 微信小程序与APP应用 开发零基础入门教程(七)---登陆注销功能与微信小程序测试号的申请

到此为止,我们只差一个退出登陆功能了。

回到index.vue页面,之前我们已经预留了退出按钮,现在给它加上功能

<button class="mybutton" type="warn" @click="logout">退出</button>

在功能区加上

logout() {
				uni.removeStorageSync('UID');
				uni.showToast({title: "您已经退出",icon: "none"});
				setTimeout(function() {
					uni.redirectTo({
						url: '/pages/login/login'
					});
				}, 1000);
			}

还是用到之前uni.removeStorageSync

完整代码如下:

index.vue

<template>
	<view class="body">
		<!-- 显示区正式开始 -->
		<view class="myfrom">
			<form @submit="goLink">
				<textarea name="mytxt" class="mytext" v-model="desc" maxlength="-1" adjust-position auto-height="true"
					placeholder="请输入文本" />
				<view class="mybutton">
					<button class="mybutton" type="primary" formType="submit">保存</button>
					<button class="mybutton" type="warn" @click="logout">退出</button>
				</view>
			</form>
		</view>
		<!-- 显示区结束 -->
	</view>
</template>

<script>
	var _self, loginUID;
	export default {
		data() {
			return {
				desc: ''
			}
		},
		methods: {
			logout() {
				uni.removeStorageSync('UID');
				uni.showToast({
					title: "您已经退出",
					icon: "none"
				});
				setTimeout(function() {
					uni.redirectTo({
						url: '/pages/login/login'
					});
				}, 1000);
			},
			goLink() {
				if (_self.desc == '') {
					uni.showToast({
						title: "内容必填",
						icon: "none"
					});
					return;
				}
				uni.request({
					url: _self.apiServer + 'add',
					method: 'POST',
					header: {
						'content-type': "application/x-www-form-urlencoded"
					},
					data: {
						'uid': loginUID,
						'txt': _self.desc
					},
					success: res => {
						_self.desc = '' //清空输入内容
						uni.showToast({
							title: res.data.datas,
							icon: "none"
						});
						setTimeout(function() {
							uni.setStorageSync("pop", 1); //给刷新标记赋值
							uni.switchTab({
								url: "/pages/list/list"
							}); //跳到 看日记页面
						}, 2000);

					}
				}); //golink结束
			},
			onLoad() {
				_self = this;
				loginUID = _self.checkLogin('/index/index');
				if (!loginUID) {
					return;
				} else(console.log(loginUID));
			}
		}
	}
</script>

<style>
	.myfrom {
		margin: 10px;
	}

	.num {
		text-align: right;
		color: gray;
		font-size: 14px;
	}

	.mytext {
		border: 1px solid #ccc;
		border-radius: 5px;
		width: 100%;
		min-height: 300px;

	}

	.mybutton {
		margin-top: 20px;
	}
</style>

以上就完成了小程序的基本开发。

众所周知,微信小程序不面向个人开放,要申请一个appid必须要企业账号,那么我们个人有没有办法不花钱申请一个呢?答案是肯定的,就是申请一个小程序测试帐号。

网址如下:微信公众平台

只要用自己的微信扫一下,就会得到申请 成功,登陆后会得到appID,把它复制出来,一会儿用到

在这里,如果自己有服务器,可以只填 request就行了

回到Hbudiler中,找到 manifest.json,将申请好的appid输入就可以使用。

 若想到直接在手机上测试,可下载 微信小程序 开发工具,运行到它上面,手机扫码测试,就可一直使用下去。

 

好了,以上就是全部内容,若觉得对学习uniapp入门有所帮忙,欢迎在文章右下方打赏。

本应用所用到的文件源程序 与数据库文件,已打包发布,若需要可整体下载。

零基本开发uniapp微信小程序教程源文件与数据库接口,简单易上手,不受版本限制-小程序文档类资源-CSDN下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

恰好

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值