uniapp使用vue3语法构建自定义导航栏,适配小程序胶囊
<template>
<view class="custom-nav">
<view class="nav-title">{{ title }}</view>
<view class="nav-operations">
<view class="nav-btn" @click="handleClick(1)">操作1</view>
<view class="nav-btn" @click="handleClick(2)">操作2</view>
</view>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue';
const title = ref('自定义标题');
const handleClick = (type: number) => {
switch (type) {
case 1:
// 操作1的逻辑
console.log('操作1被点击');
break;
case 2:
// 操作2的逻辑
console.log('操作2被点击');
break;
default:
break;
}
};
</script>
<style scoped>
.custom-nav {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
background-color: #fff;
position: relative;
box-sizing: border-box;
}
.nav-title {
font-size: 18px;
font-weight: bold;
}
.nav-operations {
display: flex;
align-items: center;
}
.nav-btn {
margin-left: 10px;
padding: 5px 10px;
border-radius: 5px;
color: #fff;
background-color: #007aff;
cursor: pointer;
}
</style>
这段代码展示了如何在uniapp中使用Vue 3的Composition API和<script setup>语法来创建一个具有自定义标题和操作按钮的导航栏。同时,它也包含了样式代码,确保导航栏在不同平台上的兼容性和视觉效果。
评论已关闭