uni-link.vue 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <text
  3. class="uni-link"
  4. :class="{
  5. 'uni-link--withline': showUnderLine === true || showUnderLine === 'true',
  6. }"
  7. :style="{ color, fontSize: fontSize + 'px' }"
  8. @click="openURL"
  9. >{{ text }}</text
  10. >
  11. </template>
  12. <script>
  13. /**
  14. * Link 外部网页超链接组件
  15. * @description uni-link是一个外部网页超链接组件,在小程序内复制url,在app内打开外部浏览器,在h5端打开新网页
  16. * @tutorial https://ext.dcloud.net.cn/plugin?id=1182
  17. * @property {String} href 点击后打开的外部网页url
  18. * @property {String} text 显示的文字
  19. * @property {Boolean} showUnderLine 是否显示下划线
  20. * @property {String} copyTips 在小程序端复制链接时显示的提示语
  21. * @property {String} color 链接文字颜色
  22. * @property {String} fontSize 链接文字大小
  23. * @example * <uni-link href="https://ext.dcloud.net.cn" text="https://ext.dcloud.net.cn"></uni-link>
  24. */
  25. export default {
  26. name: "uniLink",
  27. props: {
  28. href: {
  29. type: String,
  30. default: "",
  31. },
  32. text: {
  33. type: String,
  34. default: "",
  35. },
  36. showUnderLine: {
  37. type: [Boolean, String],
  38. default: true,
  39. },
  40. copyTips: {
  41. type: String,
  42. default: "已自动复制网址,请在手机浏览器里粘贴该网址",
  43. },
  44. color: {
  45. type: String,
  46. default: "#999999",
  47. },
  48. fontSize: {
  49. type: [Number, String],
  50. default: 14,
  51. },
  52. },
  53. methods: {
  54. openURL() {
  55. // #ifdef APP-PLUS
  56. plus.runtime.openURL(this.href);
  57. // #endif
  58. // #ifdef H5
  59. window.open(this.href);
  60. // #endif
  61. // #ifdef MP
  62. uni.setClipboardData({
  63. data: this.href,
  64. });
  65. uni.showModal({
  66. content: this.copyTips,
  67. showCancel: false,
  68. });
  69. // #endif
  70. },
  71. },
  72. };
  73. </script>
  74. <style scoped>
  75. .uni-link--withline {
  76. text-decoration: underline;
  77. }
  78. </style>