navbar-lite.uvue 3.0 KB
Newer Older
M
mehaotian 已提交
1 2
<template>
  <view class="content">
3
    <uni-navbar-lite :title="title" :is-left="isLeft" :text-color="navigationBarTextColor"></uni-navbar-lite>
M
mehaotian 已提交
4
    <scroll-view class="scroll-view" scroll-y="true">
5
      <view class="content-item" @click="onClick">
M
mehaotian 已提交
6
        <text>点击此处,将标题切换为{{isLeft?'居中':'左侧'}}显示</text>
7 8 9 10 11 12 13 14 15 16
      </view>

      <view class="content-item" @tap="setNavigationBarColor1">
        <text>设置自定义导航栏前景色白色</text>
      </view>

      <view class="content-item" @tap="setNavigationBarColor2">
        <text>设置自定义导航栏前景色黑色</text>
      </view>

M
mehaotian 已提交
17
      <view class="content-item" v-for="item in 100">
18
        <text class="text">内容:{{item}}</text>
19
      </view>
20
      <!-- <input/> -->
M
mehaotian 已提交
21 22 23 24
    </scroll-view>
  </view>
</template>

25 26
<script>
  import { state, setLifeCycleNum } from '@/store/index.uts'
M
mehaotian 已提交
27 28 29
  export default {
    data() {
      return {
30
        title: 'Hello uni-app',
31 32 33
        isLeft: false,
        navigationBarTextColor: '#000'

M
mehaotian 已提交
34 35
      }
    },
36 37 38
    methods: {
      onClick(){
        this.isLeft = !this.isLeft
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
      },
      setNavigationBarColor1() {
        uni.setNavigationBarColor({
          frontColor: '#ffffff',
          backgroundColor: '#0000',
          success: () => {
            this.navigationBarTextColor = '#fff'
            console.log('setNavigationBarColor success')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail: () => {
            console.log('setNavigationBarColor fail')
            this.setLifeCycleNum(state.lifeCycleNum - 1)
          },
          complete: () => {
            console.log('setNavigationBarColor complete')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
      },
      setNavigationBarColor2() {
        uni.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#0000',
          success: () => {
            this.navigationBarTextColor = '#000'
            console.log('setNavigationBarColor success')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          },
          fail: () => {
            console.log('setNavigationBarColor fail')
            this.setLifeCycleNum(state.lifeCycleNum - 1)
          },
          complete: () => {
            console.log('setNavigationBarColor complete')
            this.setLifeCycleNum(state.lifeCycleNum + 1)
          }
        })
      },
      // 自动化测试
      getLifeCycleNum(): number {
        return state.lifeCycleNum
      },
      // 自动化测试
      setLifeCycleNum(num: number) {
        setLifeCycleNum(num)
      },
86
    }
M
mehaotian 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
  }
</script>

<style>
  .content {
    display: flex;
    flex-direction: column;
    flex: 1;
  }

  .scroll-view {
    flex: 1;
    background-color: #f5f5f5;
    padding: 5px 0;
  }

  .content-item {
    padding: 15px;
    margin: 5px 10px;
    background-color: #fff;
    border-radius: 5px;

  }

  .text {
    font-size: 14px;
    color: #666;
  }
</style>