u-link.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view class="uni-row">
  3. <text class="text" :href="href" @click="openURL" :inWhiteList="inWhiteList">{{text}}</text>
  4. </view>
  5. </template>
  6. <script lang="uts">
  7. /**
  8. * @description u-link是一个外部网页超链接组件,在小程序内打开内部web-view组件或复制url,在app内打开外部浏览器,在h5端打开新网页
  9. * @property {String} href 点击后打开的外部网页url,小程序中必须以https://开头
  10. * @property {String} text 显示的文字
  11. * @property {Boolean} inWhiteList 是否在小程序白名单中,如果在的话,在小程序端会直接打开内置web-view,否则会只会复制url,提示在外部打开
  12. * @example * <u-link href="https://ext.dcloud.net.cn" text="https://ext.dcloud.net.cn" :inWhiteList="true"></u-link>
  13. */
  14. export default {
  15. name: 'u-link',
  16. props: {
  17. href: {
  18. type: String,
  19. default: ''
  20. },
  21. text: {
  22. type: String,
  23. default: ''
  24. },
  25. inWhiteList: {
  26. type: Boolean,
  27. default: false
  28. }
  29. },
  30. methods: {
  31. openURL() {
  32. // // #ifdef APP-PLUS
  33. // plus.runtime.openURL(this.href) //这里默认使用外部浏览器打开而不是内部web-view组件打开
  34. // // #endif
  35. // // #ifdef H5
  36. // window.open(this.href)
  37. // // #endif
  38. // // #ifdef MP
  39. // if (this.inWhiteList) { //如果在小程序的网址白名单中,会走内置webview打开,否则会复制网址提示在外部浏览器打开
  40. // uni.navigateTo({
  41. // url: '/pages/component/web-view/web-view?url=' + this.href
  42. // });
  43. // } else {
  44. // uni.setClipboardData({
  45. // data: this.href
  46. // });
  47. // uni.showModal({
  48. // content: '本网址无法直接在小程序内打开。已自动复制网址,请在手机浏览器里粘贴该网址',
  49. // showCancel: false
  50. // });
  51. // }
  52. // // #endif
  53. }
  54. }
  55. }
  56. </script>
  57. <style>
  58. .text {
  59. color: #7A7E83;
  60. font-size: 14px;
  61. line-height: 20px;
  62. /* border-bottom: 1px solid #7A7E83; */
  63. }
  64. </style>