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">
DCloud-WZF's avatar
DCloud-WZF 已提交
4 5 6 7
    <button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
    <view class="uni-common-mt">
      <text>应用本次启动路径:</text>
      <text style="margin-top: 5px">{{ launchOptionsPath }}</text>
8 9 10 11
    </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
  export default {
    data() {
      return {
        checked: false,
        homePagePath: 'pages/tabBar/component',
DCloud-WZF's avatar
DCloud-WZF 已提交
22 23 24
        launchOptionsPath: '',
        launchOptionsString: '',
        testResult: false
DCloud-WZF's avatar
DCloud-WZF 已提交
25
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
26 27 28
    },
    onReady() {
      this.compareOnLaunchRes()
DCloud-WZF's avatar
DCloud-WZF 已提交
29 30
    },
    methods: {
31
      compareOnLaunchRes() {
DCloud-WZF's avatar
DCloud-WZF 已提交
32 33
        const launchOptions = uni.getLaunchOptionsSync();
        this.launchOptionsString = JSON.stringify(launchOptions, null, 2)
DCloud-WZF's avatar
DCloud-WZF 已提交
34 35

        const app = getApp()
36
        const appOnLaunch = app.globalData.launchOptions
DCloud-WZF's avatar
DCloud-WZF 已提交
37 38 39 40

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

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