- 官方文档-uni.shoToast">1、alert提示框-官方文档-uni.shoToast
- uni.showModal(OBJECT)">2、confirm确认消息弹窗-uni.showModal(OBJECT)
- uni-popup-message
1、alert提示框-官方文档-uni.shoToast
默认是成功图标
if (res.code === 1) {
uni.showToast({
title: res.msg,
})
} else {
uni.showToast({
icon: "error",
title: res.msg
})
}
2、confirm确认消息弹窗-uni.showModal(OBJECT)
uni.showModal({
title: '提示',
content: '您还没设置接诊承诺,是否前往设置',
success: res => {
if (res.confirm) {
//确定的逻辑
console.log('用户点击确定')
} else if (res.cancel) {
//取消的逻辑
that.$set(that.payed, 'checked', !value)
console.log('用户点击取消');
}
}
});
uni-popup-message
<!-- 提示信息弹窗 -->
<uni-popup ref="message" type="message">
<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
</uni-popup>
使用方法
<template>
<view class="login">
<uni-forms :modelValue="form" ref="form" :rules="rules">
<uni-forms-item label="用户名" name="user_accout">
<uni-easyinput v-model="form.user_accout" placeholder="请输入用户名" />
</uni-forms-item>
<uni-forms-item label="密码" name="password">
<uni-easyinput v-model="form.password" placeholder="请输入密码" />
</uni-forms-item>
<button class="button" @click="submit">登录</button>
</uni-forms>
<view>
<!-- 提示信息弹窗 -->
<uni-popup ref="message" type="message">
<uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
</uni-popup>
</view>
</view>
</template>
<script>
export default {
data() {
return {
//消息
msg: {
type: 'success',
text: ''
},
//表单数据
form: {
user_accout: '',
password: ''
},
rules: {
// 对user_accout字段进行必填验证
user_accout: {
rules: [{
required: true,
errorMessage: '请输入用户名',
}]
},
password: {
rules: [{
required: true,
errorMessage: '请输入密码',
}]
}
}
}
},
methods: {
messageToggle(type, msg) {
this.msg.type = type
this.msg.text = msg
this.$refs.message.open()
},
async submit() {
let valid = await this.$refs.form.validate()
if (!valid) return
console.log('this.form', this.form);
let res = await this.$api.login.login(this.form)
console.log('登录后的返回信息', res);
if (res.code === 1) {
this.messageToggle('success', res.msg)
} else {
this.messageToggle('error', res.msg)
}
}
},
}
</script>
<style lang="scss">
.login {
padding: 20px;
}
</style>