uniapp的简单demo

index.html:

<template>
	<view class="content">
		<view class="content-space">
			<view>
				<page-head></page-head>
				</view>
				<view class="wrapper">
					<view class="avar">
						<image class="img" src="../../static/logo.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="form">
					<view class="inputWrapper">
						<input class="input" type="text" v-model="userName" value="userName" placeholder="请输入用户名"/>
					</view>
					<view class="inputWrapper">
						<input class="input" type="text" v-model="password" value="password" placeholder="请输入密码" />
					</view>
					<view class="loginBtn">
						<text class="loginText" @click="clickTest" @longtap="longtap">登录</text>
					</view>
					<view class="forgetPassword">
						<text @click="forgetPassword">找回密码</text>
					</view>
		<!-- 			<view>
						<text>学生</text>
						<view>
							<view v-for="(item, index) in students" class="persons" @click="menuClick" v-bind:id="index">{{index}} -
								{{item.name}}</view>
						</view>
					</view> -->
					<view class="select">
						<picker @change="bindPickerChange" :value="index" :range="array">
							<view class="uni-input">{{array[index]}}</view>
						</picker>
					</view>
					<view v-if="value != ''">选择器选择的key: {{key}}, value是{{value}}</view>
					
					<view>
						<text>时间控件</text>
						<picker mode="date" :value="date" start="2015-09-01" end="2017-09-01" @change="bindDateChange">
							<view class="picker">
							  当前选择: {{date}}
							</view>
						</picker>
					</view>
				</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				array: ['中国', '美国', '巴西', '日本'],
				index: 0,
				students: [{
						name: "张三",
						age: 18
					},
					{
						name: "李四",
						age: 20
					}
				],
				key: '',
				value: '',
				userName:'',
				password: '',
				date:''
			}
		},
		onLoad() {

		},
		methods: {
			clickTest: function(e) {
				console.log("点击登录按钮");
				console.log(e.target);
				console.log("登录中");
				//发送请求
				uni.request({
					url:'http://localhost:8080/dologin?username='+this.userName+'&password='+this.password,
					method:'get',
					header: {
						'context-type': "application/x-www-form-urlencoded"
					},
					//成功
					success: (res)=>{
						var str = JSON.stringify(res);
						console.log(str);
						console.log("data:", res.data);
						console.log("status:", res.statusCode)
						
						if(res.statusCode == 200){
							uni.showToast({
								title:"登录成功"
							});
							this.user = res.data.user;
						}else{
							uni.showToast({
								title:"登录失败"
							})
						}
					},
					fail: (res)=>{
						console.log("失败:",res);
					}
				})
			},
			longtap: function(e) {
				console.log(e);
				console.log('longtap');
			},
			menuClick: function(e) {
				console.log(e);
				console.log(e.target.id);
			},
			bindPickerChange: function(e) {
				console.log(e.target);
				console.log('picker发送选择改变,携带值为', e.target.value)
				this.index = e.target.value
				this.key = e.target.value;
				this.value = this.array[this.key];
			},
			forgetPassword: function(e){
				console.log("点击找回密码按钮");
				console.log(e.target);
			},
			bindDateChange:function(e){
				console.log(e);
				this.date = e.detail.value;
				console.log('type:', typeof this.date);//string
				console.log(new Date(this.date));
			}
		}
	}
</script>

<style>
	.content {
		background-color: #007AFF;
		width: 100vw;
		height: 200vh;
	}
	.content-space{
		padding: 10px;
	}
	.wrapper {
		height: 30vh;
		width: 60vh;
		display: flex;
		justify-content: center;
		align-items: flex-end;
	}

	.avar {
		width: 150upx;
		height: 150upx;
		overflow: hidden;
	}

	.avar .img {
		width: 100%;
	}

	.form {
		padding: 0 100upx;
		margin-top: 20px;
		margin-bottom: 100px;
	}

	.inputWrapper {
		width: 100%;
		height: 80upx;
		background-color: white;
		border-radius: 20px;
		box-sizing: border-box;
		padding: 0 20px;
		margin-top: 20px;
	}

	.input {
		width: 100%;
		height: 100%;
		text-align: center;
		font-size: 15px;
	}

	.loginBtn {
		width: 100%;
		height: 80upx;
		background-color: #77B3D7;
		border-radius: 50upx;
		margin-top: 50px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.loginBtn .loginText {
		color: white;
	}

	.forgetPassword {
		text-align: center;
		color: #EAF6F9;
		font-size: 15px;
		margin-top: 20px;
	}

	.persons {
		width: 750px;
		line-height: 2.2em;
	}
	.select{
		border-radius: 20px;
		width: 100%;
		height: 40px;
		background-color: #4CD964;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>

在这里插入图片描述
main.js
加了
import Vue from ‘vue’
import App from ‘./App’
import pageHead from ‘./components/page-head.vue’//新加的
Vue.component(‘page-head’,pageHead)//新加的
Vue.config.productionTip = false

App.mpType = ‘app’

const app = new Vue({
…App
})
app.$mount()

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值