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()