get-launch-options-sync.uvue 1.6 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3
<template>
  <page-head title="getLaunchOptionsSync"></page-head>
  <view class="uni-padding-wrap">
4 5 6 7 8 9 10 11
    <button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
    <view class="uni-common-mt">
      <text>应用本次启动路径:</text>
      <text style="margin-top: 5px">{{ launchOptionsPath }}</text>
    </view>
    <view class="uni-common-mt">
      <text>应用本次启动:</text>
      <text style="margin-top: 5px">{{ launchOptionsString }}</text>
DCloud-WZF's avatar
DCloud-WZF 已提交
12 13 14 15
    </view>
  </view>
</template>

16
<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18 19 20 21 22

  export default {
    data() {
      return {
        checked: false,
        homePagePath: 'pages/tabBar/component',
23 24 25
        launchOptionsPath: '',
        launchOptionsString: '',
        testResult: false
DCloud-WZF's avatar
DCloud-WZF 已提交
26
      }
27 28 29
    },
    onReady(){
      this.compareOnLaunchRes()
DCloud-WZF's avatar
DCloud-WZF 已提交
30 31
    },
    methods: {
32 33 34
      compareOnLaunchRes() {
        const launchOptions = uni.getLaunchOptionsSync();
        this.launchOptionsString = JSON.stringify(launchOptions, null, 2)
DCloud-WZF's avatar
DCloud-WZF 已提交
35 36

        const app = getApp()
37 38 39 40 41 42
        const appOnLaunch = app.globalData.launchOptions

        const isPathSame = launchOptions.path == appOnLaunch.path
        const isAppSchemeSame = launchOptions.appScheme == appOnLaunch.appScheme
        const isAppLinkSame = launchOptions.appLink == appOnLaunch.appLink
        this.testResult = isPathSame && isAppSchemeSame && isAppLinkSame
DCloud-WZF's avatar
DCloud-WZF 已提交
43
      },
44

DCloud-WZF's avatar
DCloud-WZF 已提交
45 46 47 48 49 50 51 52 53
      getLaunchOptionsSync() {
        const launchOptions = uni.getLaunchOptionsSync()
        this.launchOptionsPath = launchOptions.path
        if (launchOptions.path == this.homePagePath) {
          this.checked = true
        }
      },
    },
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
54
</script>