onLoad.uvue 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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
<template>
  <view class="uni-padding-wrap">
    <page-head title="onLoad 生命周期调用 uni api 测试" />
    <text v-if="isTrue">v-if with true</text>
    <text v-if="isFalse">v-if with false</text>
    <text v-show="isTrue">v-show with true</text>
    <text v-show="isFalse">v-show with false</text>
    <text>msg: {{ msg }}</text>
  </view>
</template>

<script lang="uts">
export default {
  data() {
    return {
      isTrue: false,
      isFalse: true,
      msg: 'default msg'
    }
  },
  onLoad(options: OnLoadOptions) {
    const type = options.get('type')
    switch (type) {
      case 'adjustData':
        this.adjustData()
        break;
      case 'navigateTo':
        this.navigateTo()
        break;
      case 'navigateBack':
        this.navigateBack()
        break;
      case 'redirectTo':
        this.redirectTo()
        break;
      case 'reLaunch':
        this.reLaunch()
        break;
      case 'switchTab':
        this.switchTab()
        break;
      case 'showToast':
        this.showToast()
        break;
      case 'showLoading':
        this.showLoading()
        break;
      case 'showModal':
        this.showModal()
        break;
      case 'showActionSheet':
        this.showActionSheet()
        break;
    }
  },
  methods: {
    adjustData(){
      this.isTrue = true
      this.isFalse = false
      this.msg = 'new msg'
    },
    navigateTo(){
      uni.navigateTo({
64
        url: '/pages/API/navigator/new-page/new-page-3'
65 66 67 68 69 70 71
      })
    },
    navigateBack(){
      uni.navigateBack()
    },
    redirectTo(){
      uni.redirectTo({
72
        url: '/pages/API/navigator/new-page/new-page-3'
73 74 75 76
      })
    },
    reLaunch(){
      uni.reLaunch({
77
        url: '/pages/API/navigator/new-page/new-page-3'
78 79 80 81 82 83 84 85 86 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
      })
    },
    switchTab(){
      uni.switchTab({
        url: '/pages/tabBar/component'
      })
    },
    showToast(){
      uni.showToast({
        title: 'test title',
        icon: 'success',
        duration: 2000
      })
    },
    showLoading(){
      uni.showLoading({
        title: 'test title',
      })
    },
    showModal(){
      uni.showModal({
        title: 'test title',
        content: 'test content',
      })
    },
    showActionSheet(){
      uni.showActionSheet({
        title: 'test title',
        itemList: ['1', '2', '3']
      })
    }
  }
}
</script>