这里写自定义目录标题
uniapp 微信小程序 纯js文件中引入自定义modal组件(无需所有页面手动引入组件)
前言
工具:uniapp
开发端:微信小程序
其他:uview 2.0
场景:接口请求统一封装中需要对接口返回token失效的情况做modal显示,引导用户退出小程序,我的想法是将modal的默认confirm按钮替换成小程序自带的退出方法:
<navigator open-type="exit" target="miniProgram" class="item"></navigator>
这样用户点击确认按钮就能退出小程序,因此uni.showModel不满足需求,需要用uview的u-model实现,也就是要在js文件中显示自定义组件。
解决方法
1.自定义组件文件/components/logout-model.vue
<template>
<view>
<u-modal ref="modal" title="登录状态失效,请重新登录" :show="showLogout" :closeOnClickOverlay="false" @close="showLogout = false"
showCancelButton>
<view style="display: flex;align-items: center;justify-content: space-around;"
slot="confirmButton">
<navigator open-type="exit" target="miniProgram" class="item">
<u-button text="确定"