SoFunction
Updated on 2025-02-28

Steps to use uniapp navigation bar components

In uni-app, the official uni-navigator component can be used to implement the function of the navigation bar.

The specific usage steps are as follows:

1. In the file, introduce the uni-navigator component:

<template>
  <view>
    <uni-navigator />
    <router-view />
  </view>
</template>
<script>
import uniNavigator from '@/components/uni-navigator/'
export default {
    components: {
        uniNavigator
    }
}
</script>

1. You can customize the style and content of the navigation bar within the component, for example:

&lt;template&gt;
  &lt;view&gt;
    &lt;view class="nav-bar"&gt;
      &lt;view class="left" @tap="goBack"&gt;return&lt;/view&gt;
      &lt;view class="title"&gt;front page&lt;/view&gt;
      &lt;view class="right"&gt;More&lt;/view&gt;
    &lt;/view&gt;
  &lt;/view&gt;
&lt;/template&gt;
&lt;script&gt;
export default {
    methods: {
        goBack() {
            ()
        }
    }
}
&lt;/script&gt;
&lt;style&gt;
.nav-bar {
    height: 44px;
    background-color: #fff;
    display: flex;
    align-items: center;
    padding: 0 15px;
    color: #333;
    border-bottom: 1px solid #e5e5e5;
}
.left {
    flex: 1;
}
.title {
    flex: 2;
    text-align: center;
}
.right {
    flex: 1;
    text-align: right;
}
&lt;/style&gt;

1. In the page where you need to use the navigation bar, just use <uni-navigator /> directly:

&lt;template&gt;
  &lt;view&gt;
    &lt;uni-navigator&gt;&lt;/uni-navigator&gt;
    &lt;view&gt;Page content&lt;/view&gt;
  &lt;/view&gt;
&lt;/template&gt;
&lt;script&gt;
export default {
}
&lt;/script&gt;

Through the above steps, you can use the uni-navigator component in uni-app to implement the function of the navigation bar. According to actual needs, you can customize the style and interactive effects of the navigation bar.

This is the end of this article about how to use the uniapp navigation bar component. For more related uniapp navigation bar component content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!