首先在定义悬浮按钮展开菜单的点击事件,注意,不是@click
是:@trigger
<uni-fab ref="fab" :pattern="pattern" :horizontal="horizontal" :content="content" @fabClick="fabClick" @trigger="trigger" />
然后定义事件:
第一个是弹出消息框
第二个是跳转其他页面,注意URL的写法。
e.index 是你点击的内容的索引
trigger(e) {
console.log(e);
// 让全部按钮false(解决选中后,其他按钮一直处于TRUE的状态)
this.content.forEach(function(item) {
item.active = false;
})
//让点击按钮TRUE
e.item.active = true;
switch (e.index) {
case 0:
uni.showToast({
title: "你点击了我"
})
break;
case 1:
uni.navigateTo({
url: "../last/last"
})
break;
}
}
DATA里定义其他变量的内容(参考)
data() {
return {
horizontal: "right",
pattern: {
color: '#7A7E83',
backgroundColor: '#fff',
selectedColor: '#007AFF',
buttonColor: '#000000',
iconColor: '#808080'
},
content: [{
iconPath: '/static/image.png',
selectedIconPath: '/static/image-active.png',
text: '船长',
active: false
},
{
iconPath: '/static/home.png',
selectedIconPath: '/static/home-active.png',
text: '答案',
active: false
},
{
iconPath: '/static/star.png',
selectedIconPath: '/static/star-active.png',
text: '分享',
active: false
},
{
iconPath: '/static/star.png',
selectedIconPath: '/static/star-active.png',
text: '黑不溜秋',
active: false
}
]
}