1、前提
1、app與小程序主體需一致,可以前往微信公眾平臺關聯。
2、小程序的場景值為1069,也就是得從app打開小程序,小程序才能喚起app。
2、vue3代碼示例
<template><view class="maxBox bgc"><button open-type="launchApp" :app-parameter="appParams" @launchapp="launchAppSuccess" @error="launchAppError"class="button">返回APP</button></view>
</template><script setup>
import { onLoad } from "@dcloudio/uni-app"
import { ref } from "vue"
onLoad(()=>{// 傳給app的參數 最好是json格式的字符串let obj = {type: 'pay',}appParams.value = `${JSON.stringify(obj)}`
})
const appParams = ref();//傳給app的參數
const launchAppSuccess = (e) => {console.log('? App 打開成功:', e);
};// 打開App失敗
const launchAppError = (e) => {console.error('?? App 打開失敗:', e);uni.showToast({title: '打開App失敗,請重試',icon: 'none'});
};
</script><style lang="scss" scoped>
.maxBox {min-height: 100vh;padding-bottom: 7vh;box-sizing: border-box;position: relative;font-size: 24rpx;.button{position: absolute;top: 40%;left: 50%;transform: translate(-50%, -50%);background-color: #0268CF;color: #fff;}
}
</style>