1、alert提示框-官方文档-uni.shoToast

image.png
默认是成功图标

  1. if (res.code === 1) {
  2. uni.showToast({
  3. title: res.msg,
  4. })
  5. } else {
  6. uni.showToast({
  7. icon: "error",
  8. title: res.msg
  9. })
  10. }

2、confirm确认消息弹窗-uni.showModal(OBJECT)

image.png

  1. uni.showModal({
  2. title: '提示',
  3. content: '您还没设置接诊承诺,是否前往设置',
  4. success: res => {
  5. if (res.confirm) {
  6. //确定的逻辑
  7. console.log('用户点击确定')
  8. } else if (res.cancel) {
  9. //取消的逻辑
  10. that.$set(that.payed, 'checked', !value)
  11. console.log('用户点击取消');
  12. }
  13. }
  14. });

uni-popup-message

参考:官方文档-uni-popup-message
image.png

  1. <!-- 提示信息弹窗 -->
  2. <uni-popup ref="message" type="message">
  3. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  4. </uni-popup>

使用方法

  1. <template>
  2. <view class="login">
  3. <uni-forms :modelValue="form" ref="form" :rules="rules">
  4. <uni-forms-item label="用户名" name="user_accout">
  5. <uni-easyinput v-model="form.user_accout" placeholder="请输入用户名" />
  6. </uni-forms-item>
  7. <uni-forms-item label="密码" name="password">
  8. <uni-easyinput v-model="form.password" placeholder="请输入密码" />
  9. </uni-forms-item>
  10. <button class="button" @click="submit">登录</button>
  11. </uni-forms>
  12. <view>
  13. <!-- 提示信息弹窗 -->
  14. <uni-popup ref="message" type="message">
  15. <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
  16. </uni-popup>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. //消息
  25. msg: {
  26. type: 'success',
  27. text: ''
  28. },
  29. //表单数据
  30. form: {
  31. user_accout: '',
  32. password: ''
  33. },
  34. rules: {
  35. // 对user_accout字段进行必填验证
  36. user_accout: {
  37. rules: [{
  38. required: true,
  39. errorMessage: '请输入用户名',
  40. }]
  41. },
  42. password: {
  43. rules: [{
  44. required: true,
  45. errorMessage: '请输入密码',
  46. }]
  47. }
  48. }
  49. }
  50. },
  51. methods: {
  52. messageToggle(type, msg) {
  53. this.msg.type = type
  54. this.msg.text = msg
  55. this.$refs.message.open()
  56. },
  57. async submit() {
  58. let valid = await this.$refs.form.validate()
  59. if (!valid) return
  60. console.log('this.form', this.form);
  61. let res = await this.$api.login.login(this.form)
  62. console.log('登录后的返回信息', res);
  63. if (res.code === 1) {
  64. this.messageToggle('success', res.msg)
  65. } else {
  66. this.messageToggle('error', res.msg)
  67. }
  68. }
  69. },
  70. }
  71. </script>
  72. <style lang="scss">
  73. .login {
  74. padding: 20px;
  75. }
  76. </style>