uni-link.vue 1.7 KB

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