在 Nativescript ios & Android 中制作一个简单的 href 链接



晚安,

我有一个简单的问题,如何在VueJs&Ios&的Nativescript;安卓

我有一个网上商店,我希望用户只需点击我应用程序中的链接/按钮就可以访问这家商店。点击将在手机上启动浏览器。

假设我有www.shop.com,我想要一个这样的链接:我的链接。

谢谢。

这里有一个StackBlitz示例,说明如何做到这一点。

如果你只是想看看,而不是运行它,那么重要的部分就在这里。简而言之,使用link类的Label将其设置为链接样式,并使用openUrl在浏览器中启动链接。

<template>
<Page>
<ActionBar>
<Label text="Home" class="font-bold text-lg" />
</ActionBar>
<GridLayout>
<Label
class="text-xl align-middle text-center link"
:text="linkText"
@tap="openLink"
/>
</GridLayout>
</Page>
</template>
<script lang="ts">
import Vue from 'nativescript-vue';
import { Utils } from '@nativescript/core';
export default Vue.extend({
computed: {
linkText() {
return 'My Link';
},
},
methods: {
openLink() {
Utils.openUrl('https://nativescript.org');
},
},
});
</script>
<style>
.link {
color: #0645ad;
text-decoration: underline;
}
</style>

如果你不想依赖内置的Utils.openUrl((,你可以直接调用本地API,例如在iOS:上这样

import { Application } from '@nativescript/core';
const app: UIApplication = Application.ios.nativeApp;
const options = NSDictionary.dictionary<string, any>();
const callback = (success) => {
console.log('openUrl: ', success);
};
app.openURLOptionsCompletionHandler(NSURL.URLWithString('https://nrk.no'), options, callback);