写日记界面的制作:
打开index.vue页面,先把 上一节中login.vue界面的所有代码直接拷贝过来,替换当前页面,然后进行以下修改:
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 placeholder="请输入文本" />
<view class="mybutton">
<button class="mybutton" type="primary" formType="submit">保存</button>
<button class="mybutton" type="warn" >退出</button>
</view>
</form>
</view>
<!-- 显示区结束 -->
</view>
</template>
<script>
var _self, loginUID;
export default {
data() {
return {
desc: ''
}
},
methods: {
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>
修改点:
- 将原 <input v-model="pwd" placeholder="请输入密码" password adjust-position />
修改为 <textarea name="mytxt" class="mytext" v-model="desc" maxlength="-1" adjust-position auto-height="true" placeholder="请输入文本" />
将 input 单行输入框 换成了多行输入框textarea,注意要加上 maxlength="-1",否则,系统默认只能输入140个字,改后就不受限制,举一反三,如果想限制字数,直接把 -1 改成想要的字数就可以了。
auto-height 表示行数自动随着字数变化。
- 功能区 methods方法 url.request中:
url: _self.apiServer + 'add', 这个表示要做的是新增功能
data: { 'uid': loginUID,'txt': _self.desc } 更换了要传递的内容 - 最重要的一个知识点:
uni.setStorageSync("pop", 1); //给刷新标记赋值
上一节我们说了,由于 uni.switchTab 不能传递参数,所以,我们要在这里做一个标记,告诉list页面,准备进行看日记页面的刷新工作。 - 这里我先预留一下退出登陆按钮,在最后一节再添加相关的功能
其它内容的相关知识请看上一节。