uni-link.vue 1.8 KB

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