效果图
util.js
/**
* @param {Object} msg
* 自定义显示toast
*/
export const showToast = msg => {
const ctx = getCurrentPages(), _t = ctx[ctx.length - 1];
if(_t) {
_t.$vm.$refs['toast'].show({
title: msg,
duration: 2500
});
}else
uni.showToast({
title: msg,
icon: 'none',
duration: 2500
})
}
pages.json
"insetLoader": {
"config": {
"Toast": "<Toast ref='toast' />"
},
// 挂载的组件名
"label": ["Toast"],
// 插入的根元素的标签类型
"rootEle": "view"
}
安装插件
npm install vue-inset-loader
vue.config.js
const path = require('path')
module.exports <