uni-link.vue 1.8 KB

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